I have been looking for resources about inheritance in OAS3 but the closest i get is https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md and the above did not have answer i am looking for.
This is the working example
components:
schemas:
Pet:
properties:
no_legs:
description: "Number of legs"
type: number
example: 4
Duck:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
no_legs:
example: 2
properties:
no_legs:
description: 'Number of webbed feet'
Failing example that was inspired by the spec
Duck:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
no_legs:
description: 'Number of webbed feet'
example: 2
My questions are
Is the overriding feature i am looking at available/supported?
If so what is the appropriate way of doing it?
I understood that i can use composition to tackle this issue but i will have a lot of the definition being repeated.
Yes, that's essentially the way to go about overriding properties. What sort of error are you getting on your failing example? It works just fine at https://editor.swagger.io/ at least. Did you remember to specify openapi: 3.0.0 at the root of your document?
Note that the following two definitions are identical:
Duck:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
no_legs:
description: 'Number of webbed feet'
example: 2
Duck:
allOf:
- $ref: '#/components/schemas/Pet'
properties:
no_legs:
description: 'Number of webbed feet'
example: 2
Related
The idea is taken from here stack-overflow
After adding a parameter that is supposed do allow dynamic query parameters, it gives error.
Query Example:
/pets:
get:
description: |
Returns all pets
operationId: findPets
parameters:
- name: params
in: query
required: false
schema:
type: object
# If the parameter values are of specific type, e.g. string:
# additionalProperties:
# type: string
# If the parameter values can be of different types
# (e.g. string, number, boolean, ...)
additionalProperties: true
# `style: form` and `explode: true` is the default serialization method
# for query parameters, so these keywords can be omitted
style: form
explode: true
responses:
'200':
description: pet response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
Executing a query, returns
{"message":"Cannot convert undefined or null to object"}
To Reproduce
Clone this repository
run npm install
run npm start
run curl http://localhost:3000/v1/pets\?type\=dog\&limit\=10\&test\=query
Expected behavior
It must allow all the query strings
This was the bug in the express-openapi-validator package.
It is now fixed in v4.4.2
To test out the functionality, see this example project
I'm building a simple OpenAPI 3 YAML specification like this:
paths:
/query:
get:
parameters:
- $ref: '#/components/parameters/bookid'
components:
parameters:
bookid:
in: query
name: bookid
required: false
schema:
format: integer
type: number
Now, I'd like to use the common bookid parameter but overriding the required value from false to true. For example (that doesn't work!!!):
paths:
...
/query2:
get:
parameters:
- $ref: '#/components/parameters/bookid'
required: true # <--- ???
Is there a way to do that?
This is not supported. You need separate parameter definitions for required and optional parameters.
As of OpenAPI 3.1, you can only override the description of a referenced parameter, but not other attributes (required, name and others).
# openapi: 3.1.0
parameters:
# This works
- $ref: '#/components/parameters/bookid'
description: Custom description
# This won't work - cannot override attributes other than "description"
- $ref: '#/components/parameters/bookid'
required: true
Here are existing feature requests:
Extend/override properties of a parameter
Allow required as sibling of $ref (like summary/description)
I am working on a topology using apache flux. Currently, strom fetches messages from beginning but I want it to fetch only the latest messages from kafka.
I am writing topology in YAML file.
This is how my spoutConfig looks like:
- id: "stringScheme"
className: "org.apache.storm.kafka.StringScheme"
- id: "stringMultiScheme"
className: "org.apache.storm.spout.SchemeAsMultiScheme"
constructorArgs:
- ref: "stringScheme"
- id: "zkHosts"
className: "org.apache.storm.kafka.ZkHosts"
constructorArgs:
- "172.25.33.191:2181"
- id: "spoutConfig"
className: "org.apache.storm.kafka.SpoutConfig"
constructorArgs:
- ref: "zkHosts"
- "blockdata"
- ""
- "myId"
properties:
- name: "scheme"
ref: "stringMultiScheme"
- name: "ignoreZkOffsets"
value: true
- name: "startOffsetTime"
ref: "XXXXXXXXX"
Now, I am stuck. How do I set startOffsetTime to proper function to get only the latest messages from kafka?
I have tried ref:"LatestTime", but no matter what I put in there, it give me error :
java.lang.IllegalArgumentException: Can not set long field org.apache.storm.kafka.KafkaConfig.startOffsetTime to null value
I believe Flux can handle calling static factory methods.
- id: "startingOffsetTime"
className: "kafka.api.OffsetRequest"
factory: "LatestTime"
and then use it in your SpoutConfig definition like
properties:
- name: "startOffsetTime"
ref: "startingOffsetTime"
I haven't tested this, but I think it should work. The ability to call static factory methods was merged a while back https://issues.apache.org/jira/browse/STORM-2796, but it seems to be missing from the documentation. I've raised an issue to update the docs https://issues.apache.org/jira/browse/STORM-3086.
In case you'd like to see an example of this feature, take a look at https://github.com/apache/storm/blob/master/flux/flux-core/src/test/resources/configs/config-methods-test.yaml#L38
There is a swagger 2.0 file I am dealing with, where I want to specify that the error code from my response can only be USERNAME_VALIDATION_FAILED or EMAIL_VALIDATION_FAILED. This is due to a swagger-ui view of the swaggerfile where every response error can have the 20 error codes defined in the Error code enum.
How to limit the possible error codes for a specific response?
In my swaggerfile there is the request
/register:
post:
...
parameters:
...
responses:
...
400:
description: Username or email validation failed, possible values for code are USERNAME_VALIDATION_FAILED, EMAIL_VALIDATION_FAILED
schema:
$ref: '#/definitions/Error'
and my Error looks like
Error:
type: object
properties:
code:
type: string
enum:
- USERNAME_VALIDATION_FAILED
- EMAIL_VALIDATION_FAILED
- USERNAME_EXISTS
- ...
I would suggest something like
schema:
$ref: '#/definitions/Error.code.of(USERNAME_VALIDATION_FAILED, EMAIL_VALIDATION_FAILED)'
You can't override the enum of a property, so you need a separate model:
RegistrationError:
type: object
properties:
code:
type: string
enum:
- USERNAME_VALIDATION_FAILED
- EMAIL_VALIDATION_FAILED
Error:
type: object
properties:
code:
type: string
enum:
- USERNAME_VALIDATION_FAILED
- EMAIL_VALIDATION_FAILED
- USERNAME_EXISTS
- ...
If the error models have common properties, you can "inherit" them from a base model to reduce code duplication:
BaseError:
type: object
properties:
message:
type: string
RegistrationError:
allOf:
- $ref: "#/definitions/BaseError"
- type: object
properties:
code:
type: string
enum:
- USERNAME_VALIDATION_FAILED
- EMAIL_VALIDATION_FAILED
Error:
allOf:
- $ref: "#/definitions/BaseError"
- type: object
properties:
code:
type: string
enum:
- USERNAME_VALIDATION_FAILED
- EMAIL_VALIDATION_FAILED
- USERNAME_EXISTS
- ...
I face issue with my swagger file :
swagger: '2.0'
paths:
/currencies:
get:
responses:
'200':
description: ''
summary: 'list currencies summary'
x-auth-type: None
x-throttling-tier: Unlimited
produces:
- application/json
description: 'list currencies description'
'/currencies/{currencieId}':
get:
responses:
'200':
description: ''
description: 'Single currency description'
parameters:
- name: currencieId
in: path
allowMultiple: false
required: true
type: string
description: 'paramter description'
summary: 'Single currency'
x-auth-type: None
x-throttling-tier: Unlimited
produces:
- application/json
info:
title: MDM
version: v1
Here is my issue :
✖ Swagger Error
Not a valid parameter definition
Jump to line 20
Details
Object
code: "ONE_OF_MISSING"
params: Array [0]
message: "Not a valid parameter definition"
path: Array [5]
0: "paths"
1: "/currencies/{currencieId}"
2: "get"
3: "parameters"
4: "0"
schemaId: "http://swagger.io/v2/schema.json#"
inner: Array [2]
level: 900
type: "Swagger Error"
description: "Not a valid parameter definition"
lineNumber: 20
Issue in swagger editor
I am a bit lost with that ....
Thanks for your help.
Julien
Remove allowMultiple: false from the definition of the currencieId parameter. That eliminates the error.
The allowMultiple keyword does not exist in the OpenAPI (fka Swagger) Specification 2.0. It was used in v1.2, but in 2.0 it was replaced with type: array and collectionFormat.
allowMultiple: false is not correct