Uh oh!
There was an error while loading. Please reload this page.
[core] Add type and format properties to model of inline response - #6153
Conversation
Uh oh!
There was an error while loading. Please reload this page.
5114dcc to
8698e0eCompareybelenko
commented
May 31, 2020
After a few experiments with schema: definitions:
Test:
properties:
propertyA:
type: stringproeprtyB:
type: string
Well, let's consider output Since it's a core bug I subscribe @OpenAPITools/generator-core-team |
jimschubert
left a comment
There was a problem hiding this comment.
I don't think this is a bug necessarily, since any schema without a type defined is an object implicitly. Add a type: object to the output when it exists in the input makes sense, but consider that someone might think this is now a bug when they don't define type: object for input but it's now in the output.
I do think it makes sense to have this, however. OAS 3.1 will have a type: null and I wouldn't be surprised if that became the default.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Thanks for the review, Jim!
Is it possible to check that input definition contains I've read OAS 3.0.3 spec yesterday and can't recall anything like "consider schema without |
ybelenko
commented
Jun 9, 2020
@jimschubert The reason why I ask about parsing schemas without
And maybe it's not relevant to current issue directly, but @richardwhiuk said:
|
8698e0e to
49de85eComparesebastien-rosset
commented
Jun 9, 2020
I don't think a schema without type means it is an object implicitly. Where do you see that specified? I think no type means the type can be anything. For example below the value of foo:
type: objectproperties:
int_prop:
type: integerany_prop:
description: a property whose value can be an integer, boolean, number, array or object.
|
There was a problem hiding this comment.
Here I agree type: object was missing. It it there in the original document (modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml), it makes sense to add it.
There was a problem hiding this comment.
In JSON schema, allOf means a compliant validator must validate the payload against all of the nested schemas under allOf. Since Animal is already specified as a type: object, it's redundant and verbose to add type: object here.
sebastien-rosset
commented
Jun 9, 2020
IMO, |
sebastien-rosset
commented
Jun 9, 2020
In #6150, you state that type is required property, but that is not correct. The type keyword is not required. |
ybelenko
commented
Jun 9, 2020
Yeah, my mistake. Current OAS 3.0 Specification doesn't declare For me(I need to parse OAS in my own tool) it means that I shouldn't throw exceptions when schema doesn't contain |
sebastien-rosset
commented
Jun 9, 2020
Just FYI, the relevant sections of the JSON schema are:
and
So if a keyword is not present, there is no constraint assertion. There is nothing to guess. Also here I think it's better to use the word keyword rather than property because "property" means something else in JSON schema. |
ybelenko
commented
Jun 9, 2020
My case is a bit different. I'm working on a data mocker. When mock tool gets input schema without |
sebastien-rosset
commented
Jun 9, 2020
First, let me point out we make a distinction between "any object" versus free form object. The "any type" schema is even more generic than free-form. It's not necessarily an object. It could be an object, but also an array, the null value, an integer, number, string or boolean. Are you saying the purpose of the data mocker is to automatically generate mock data based on the OpenAPI schema? |
ybelenko
commented
Jun 9, 2020
That's how I see it. The main advantage of OAS is auto generation of application parts. OAS perfectly describes how request and response looks like. I've spent so many time on writing server unit tests which can be autogenerated. Usually I need to write fixtures of valid and invalid requests. And that is the place where mock or faker engine fits perfectly. There are developers that already shows interest in mock server. This feature helps to get demo server as soon as possible. #3545 Here is the tool I make btw - OpenAPI Data mocker. |
I would consider the following scenarios that don't have the components:
freeFormSchema:
description: free form object (must be a dictionary).It would be very unusual to write the schema that way, but since the schemamust match ALL of the allOf nested schema, that means the top-level schemamust be an object.allOf:
- type: objectadditionalProperties: trueanyTypeSchema:
description: any type, the payload can be anything (boolean, integer, null, number,string, object, array). Ideally the mock server would be able to generate all ofthese values.unusualSchemaWithConstraintsAndNoType:
description: this is (imo) a very unusual way to specify a schema.The type can be anything (boolean, integer, null, number,string, object, array)When the value is a number, it cannot be more than 10.If the value is a string, the length of the string cannot be more than 20.Any boolean value is ok.If the value is an array, it cannot have more than 30 items.maximum: 10maxLength: 20maxItems: 30nothingSchema:
description: no JSON payload can ever match this schemaallOf:
- type: string
- type: booleancomposedSchemaAllOf:
description: The type of this schema depends on the type of the nested schemas.The nested schemas must be of the same type, except the scenario when A isan integer and B is a number.allOf:
- $ref: '#/components/schemas/A'
- $ref: '#/components/schemas/B'composedSchemaOneOf:
description: The type of this schema depends on the type of the nested schemasoneOf:
- $ref: '#/components/schemas/A'
- $ref: '#/components/schemas/B'composedSchema:
description: The type of this schema depends on the type of the nested schemas.The nested schemas may have different types.anyOf:
- $ref: '#/components/schemas/A'
- $ref: '#/components/schemas/B' |
ybelenko
commented
Jun 9, 2020
I don't think so. As far as I remember encoding |
What I mean is suppose the payload is: "hello"A compliant validator must validate the payload against all If the payload is the value |
ybelenko
commented
Jun 9, 2020
Ohhh, now I see. Thanks for so many test cases. I asked community for weeks with no response at all. Thanks again Sebastien! |
ybelenko
commented
Jun 10, 2020
So, in a conclusion I need to fix behaviour with 4 keywords(
Model:
# type can be omitted because of allOf[1] schematype: objectallOf:
- properties:
foobar:
type: string
- type: objectproperties:
foobaz:
type: string
Model:
# type can be omitted because of allOf[1] schematype: objectanyOf:
- type: string
- type: object
Model:
# type can be omitted because of allOf[1] schematype: objectoneOf:
- type: integer
- type: object
|
This can get tricky because it recursive, so you can't just look at the direct subschema. Example: A:
allOf:
- $ref: '#/components/schemas/B'B:
allOf:
- $ref: '#/components/schemas/C'C:
allOf:
- $ref: '#/components/schemas/D'Also, if you are looking for corner cases, here is one that you probably won't see very often :-) Model:
anyOf:
- allOf:
- type: stringmaxLength: 15
- type: boolean
- $ref: '#/components/schemas/D'allOf:
- type: stringminLength: 10
- pattern: [a-z]{3,50}oneOf:
- type: stringThis is a complicated way to specify the value must be a string between length 10 and 15, and all characters must be lowercase a-z, with possibly some constraints coming from |
49de85e to
267e090CompareUh oh!
There was an error while loading. Please reload this page.
This reverts commit f88dcb13594b3e21b734b8b1569ca29bcbf9cb13.
1550753 to
cdf4d35Compareybelenko
commented
Jul 25, 2020
Small offtopic. This PR should be merged as temporarily solution from my point of view. I think that we'll end up with parsing spec file directly anyway. It's hard to store all spec data in codegen variables if it's even possible(I don't know how to store deeply nested values in mustache variables). Maybe server framework should be able to parse full spec( For instance we have stale issue #4513 which cannot be solved because of codegen |
ybelenko
commented
Aug 1, 2020
@wing328 or @jimschubert could you check and merge? It's 3 months already. |
jimschubert
commented
Aug 1, 2020
@ybelenko this has been open for 3 months, but you have commits up to 15 days ago. Realize when you make additional changes and force-push, things have to be reviewed again. If @sebastien-rosset is content with your recent changes, I'm fine to have this merged. |
ybelenko
commented
Aug 1, 2020
Sure, but I didn't drop any commit. I rebase and force push to:
I've requested your review again at June 13th. |
jimschubert
left a comment
There was a problem hiding this comment.
Re-approving but awaiting feedback from others whether their concerns have been addressed.
jimschubert
commented
Aug 1, 2020
@ybelenko just curious, why was rebase necessary rather than merging master up to your branch? The rebase and force-push will often make inline review comments and their resolutions no longer accessible. It also makes it so that contributors can't tell whether this was just a master sync or if there was new work that requires another review. Reviewing each of your 4 force pushes, I now see there were no changes since Jun 9, but it's unlikely that any contributors are going to dig into force push history when re-reviewing a pull request. My question still remains that if your last true change was June 9, and concerns were still voiced on June 10, whether or not those concerns are blockers before merge. |
I've been in a project where
Beside, it was the first time I've changed my solution completely in the middle of PR. I agree that changes was hard to review. My bad.
I don't know whether my fix solves @dang-gyg issue because there is no details. I think that @sebastien-rosset concerns solved because I decided to fix it inside |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
sebastien-rosset
commented
Aug 1, 2020
The changes look good. I did make a couple of suggestions to add code comments. This is to avoid the element of surprise/confusion when future code maintainers will read the source code. It's not immediately obvious the |
Thanks @sebastien-rosset. I'll add those comments and push. Then I'll call everybody to check again 😄 |
ybelenko
commented
Aug 2, 2020
Obviously CI failure isn't related to changes, because I modified comments only. |
sebastien-rosset
commented
Aug 2, 2020
thanks! lgtm |
jimschubert
commented
Aug 3, 2020
CircleCI was a timeout I have the type/format change and 20 other attributes were weren't copying in #7106, so I'll merge this and retain your comments when I merge it up into my PR. |
* master: [core] Add type and format properties to model of inline response (#6153) [PowerShell] better publishing workflow (#7114) [aspnetcore] Typo issues in docs and generated code (#7094) fix http signaure auth in build.sbt (#7110) fix for the issue facing spec invlolving arrayschema structure with ref (#6310) [csharp-netcore] added cancellation tokens to async calls (#7077) [PS] Allow CI to publish the module (#7091) [Dart] Treat float as double (#6924) [Java][jersey2]Fix gradle HttpSignatureAuth dependencies (#7096) move maven,gradle tests to shipppable ci (#7108)
* master: (129 commits) [typescript-axios] add promise to bearer and oauth tokens (#7132) update doc [REQ] Added enumClassPrefix option to Go server generation (#7008) [Java][jersey2] Add helper methods for oneOf Java classes (#7115) [Kotlin][Retrofit2] fix missing import for file (#7121) adding handling for epoch dates in javascript ApiClient mustache file (#6497) (#6504) update doc comment out cpanm in travis [Kotlin] Rxjava3 support (#6998) [BUG][JAVA] Fix error handling in okhttp-gson async api client (#7089) Update to reset httpRepsonse.Body (#6948) [php-lumen] Set required PHP version to ^7.2.5 (#6949) [contrib][docs] Assert importance of title/description/repro steps (#7103) ISSUE-4222: Prevent conflicts with accept(s) local variables in generated Java RestTemplate ApiClient (#7101) [bug][core] Copy all attributes (not properties) on composed schemas when flattening models (#7106) [core] Add type and format properties to model of inline response (#6153) [PowerShell] better publishing workflow (#7114) [aspnetcore] Typo issues in docs and generated code (#7094) fix http signaure auth in build.sbt (#7110) fix for the issue facing spec invlolving arrayschema structure with ref (#6310) ...
I tried to copy original
Schemainstance, but failed I guess. Need a small help from a core team.Closes#6150
PR checklist
./bin/(or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh,./bin/openapi3/{LANG}-petstore.shif updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).master,4.3.x,5.0.x. Default:master.