Skip to content

Instantly share code, notes, and snippets.

@RonnyPfannschmidt
Last active July 2, 2024 13:10
Show Gist options
  • Save RonnyPfannschmidt/8a852d04df4a786adf79156b4b265ae8 to your computer and use it in GitHub Desktop.
Save RonnyPfannschmidt/8a852d04df4a786adf79156b4b265ae8 to your computer and use it in GitHub Desktop.
openapi spec - show distinct needed tpyes
openapi: 3.0.0
info:
title: Pet Store Service
description: This is a sample server Petstore server.
version: 0.0.0
tags: []
paths:
/:
post:
operationId: Ratings_create
parameters: []
responses:
'200':
description: The request has succeeded.
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/NamedRating'
/{id}:
post:
operationId: Ratings_update
parameters:
- name: id
in: path
required: true
schema:
type: integer
responses:
'200':
description: The request has succeeded.
requestBody:
required: true
content:
application/json:
schema:
anyOf:
- $ref: '#/components/schemas/NamedRating'
- $ref: '#/components/schemas/PatchRatingNumber'
components:
schemas:
NamedRating:
type: object
required:
- name
properties:
name:
type: string
rating:
type: integer
description: may be left out
PatchRatingNumber:
type: object
required:
- rating
properties:
rating:
type: integer
nullable: true
description: this one needs a value
servers:
- url: https://example.com
description: Single server endpoint
variables: {}
import "@typespec/http";
import "@typespec/rest";
using TypeSpec.Http;
using TypeSpec.Rest;
/**
* This is a sample server Petstore server.
*/
@service({
title: "Pet Store Service",
})
@server("https://example.com", "Single server endpoint")
namespace Ratings;
model NamedRating {
name: string;
@doc("may be left out")
rating?: integer;
}
model PatchRatingNumber {
@doc("this one needs a value")
rating: integer | null;
}
interface Ratings {
op create(@body rating: NamedRating): {};
@route("/{id}")
@post
op update(id: integer, @body update: NamedRating|PatchRatingNumber): {};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment