-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve examples #99
Comments
@KES777 There's not really any difference between PUT and POST from the perspective of the OpenAPI description. Is there some specific thing you are looking for an example to demonstrate? |
No. Just for purpose of completeness |
Today I have good question. and can describe specific thing which is worth to demonstrate.
To create new country I have next
Thus to create country we send next json:
It is OK. Only But when we update this country we can send one of: The schema may looks like:
But this will restrict us to send next API request
Which will cause validation error:
It seems I should define it via
But this also requires How to describe: expect any of properties in Country? |
@KES777, If I understand correctly, you want to have different constraints on the POST request, where you're creating a new Country, vs. the PUT request, where you're updating an existing country. I think you can accomplish this with separate schema objects, defined like this: components:
schemas:
# Base type for a Country, with minimal constraints
BaseCountry:
type: object
properties:
id:
type: integer
readOnly: true
code:
type: string
name:
type: string
# Country with at least one known property, used for PUT or PATCH requests.
NonEmptyCountry:
allOf:
- $ref: "#/components/schemas/BaseCountry"
# require at least one known property value.
minProperties: 1
additionalProperties: false
# additionalProperties doesn't have visibility into the inherited properties,
# so re-declare these:
properties:
id:
name:
code:
# Country object in its complete, steady state
Country:
allOf:
- $ref: "#/components/schemas/NonEmptyCountry"
required:
- id Your Your Responses that include an object representation should use |
@tedepstein Thanks. You understand correct. |
@tedepstein: I should not redeclare |
Here is my variant of schema. I did it slightly differently. Maybe will be useful for others |
We are moving supplementary examples to the learn.openapis.org site, so I am going to transfer this issue so it's easier to see what issues are for the separate examples and what are for the examples embedded in the spec. See this issue for the decision: |
None of examples do not provide
put
exampleThe text was updated successfully, but these errors were encountered: