Skip to content

Conversation

@deekshas8
Copy link
Contributor

@deekshas8 deekshas8 commented Aug 30, 2024

Closes https://github.com/SAP/cloud-sdk-backlog/issues/1238

  • Schema with type object have 3 possible values in Azure spec: (Whether all are correct is another point). The below are now handled in the generation
    • The normal
      type: object
           properties:
             error:
               $ref: '#/components/schemas/error'
      
    • multiple at same level (This is normalized as only allOf)
      error:
            type: object
            allOf:
              - $ref: '#/components/schemas/errorBase'
            properties:
              ...
      
    • allOf Inheritance (type: Object is ignored and is treated only as allOf)
      contentFilterDetectedResult:
            type: object
            allOf:
              - $ref: '#/components/schemas/contentFilterResultBase'
              - properties:
                  detected:
                    ....
           required:
              - detected
      
  • In 3rd example, if detected is required, it is not yet considered in generation process.

@deekshas8 deekshas8 changed the title add schema prefix option Fix: Adjust openapi generator for azure spec Aug 30, 2024
@deekshas8 deekshas8 changed the title Fix: Adjust openapi generator for azure spec chore: Adjust openapi generator for azure spec Aug 30, 2024
@deekshas8 deekshas8 marked this pull request as ready for review August 30, 2024 13:10
Comment on lines 50 to 57
if (isAllOfSchema(schema)) {
return {
...(schema.allOf?.length &&
parseXOfSchema(schema, refs, 'allOf', options)),
...((schema.properties || 'additionalProperties' in schema) &&
parseObjectSchema(schema, refs, options))
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[req] I still believe combining allOf and type: object is just incorrect, therefore if both are set and we know a few cases where services do that, I would allow that and treat it as allOf only. Parsing other properties and handling them a certain way is just guess work and as far as I know we haven't seen examples of that before, did we?

Therefore my suggestion is to just move this down below anyOf so objects are prioritized lower.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pp] I think it could be helpful to have a warning when generating this (incorrect) type. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added info log if allOf and properties are at the same level. It is restructured into the "inheritance" type as discussed

return {
[xOf]: (schema[xOf] || []).map(entry => parseSchema(entry, refs, options))
[xOf]: (schema[xOf] || []).map(entry =>
parseSchema({ ...entry, required }, refs, options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[req] In this case the schema would overwrite anything that is required in the actual entry. We should at least merge this, but I think we shouldn't do this at all.

Copy link
Contributor Author

@deekshas8 deekshas8 Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this for now. Required will be considered in a followup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merge this now. Have also added a test for it.

@deekshas8 deekshas8 requested a review from marikaner September 9, 2024 12:51
Copy link
Contributor

@marikaner marikaner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we could split PRs like this one by concern: allof + properties and schema naming.

I have some more questions:

  1. I assume the schema names including the prefix go through the unique name generator? Maybe a test would be nice?
  2. I think the name prefix is not a hidden property. I think that is ok, but then please make sure to document it in the portal as well.
  3. Consider not only supporting properties for the all of schemas, but also additionalProperties.

}

if (schema.allOf?.length) {
if (schema.properties) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[req] I think this needs to be handled for anyOf and oneOf as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I had somehow missed this again. I moved the logic to the parseXOfSchema function now.

@deekshas8 deekshas8 requested a review from marikaner September 13, 2024 07:47
@deekshas8 deekshas8 requested a review from marikaner September 16, 2024 13:25
Copy link
Contributor

@marikaner marikaner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, I just left one question

Comment on lines 252 to 254
schema.properties ||
(schema.additionalProperties &&
typeof schema.additionalProperties === 'object')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] Shouldn't we add Record<string, any> to the type if schema.additionalProperties = true?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the answer to the question above is yes, you could consider extracting a function to check whether the given schema is an object schema and reusing it for the object check above as well.

Copy link
Contributor Author

@deekshas8 deekshas8 Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if the object has properties and schema.additionalProperties = true then it will add it. If its:

type: object
allOf:
  - ...
additionalProperties: true

then I think not. I probably can just check for schema.additionalProperties instead of

schema.additionalProperties && typeof schema.additionalProperties === 'object'

and that should already fix it. Honestly I am forgetting now why I checked for object type. Let me try.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this after removing && typeof schema.additionalProperties === 'object' check. And it works.

@deekshas8 deekshas8 merged commit 37b0397 into main Sep 16, 2024
14 checks passed
@deekshas8 deekshas8 deleted the openapi-generator-update branch September 16, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants