Skip to content
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

OA 3.1. support #312

Open
marko92milinkovic opened this issue Jan 4, 2024 · 11 comments
Open

OA 3.1. support #312

marko92milinkovic opened this issue Jan 4, 2024 · 11 comments
Labels
oas3.1 OpenAPI 3.1 specification support

Comments

@marko92milinkovic
Copy link

marko92milinkovic commented Jan 4, 2024

Does ng-openapi-gen support OA 3.1?

@marko92milinkovic
Copy link
Author

marko92milinkovic commented Jan 4, 2024

I have impression that it can't work with nullability feature in OpenApi 3.1 which is described as array:

        "schemas": {
            "SomeResource": {
                "description": "",
                "properties": {
                    "someProperty": {
                        "type": [
                            "string",
                            "null"
                        ]
                    },

The problematic code seems to be inside collectObject(schema, propertiesByName) function.
Could you please check if the library can work with this nullability notation? If not, is there a plan to support this feature from OA 3.1?

@juneidy
Copy link
Contributor

juneidy commented Jan 5, 2024

This should work:

type: string
nullable: true

@marko92milinkovic
Copy link
Author

Hi @juneidy ,
You're correct. The following notation is indeed valid in OpenAPI 3.0:

type: string
nullable: true

However, OpenAPI 3.1 introduces an alternative format to specify the type property as an array:

"type": ["string", "null"]

This is the format my library (NelmioApiDocBundle) uses for generating API specifications compliant with OpenAPI 3.1.0. The choice of library, though, isn't particularly relevant to the discussion.

From our testing, it appears that ng-openapi-gen hasn't yet adopted this new syntax. Does anyone know if or when ng-openapi-gen plans to support this format? Thanks for any insights.

@cgearing
Copy link

It also doesn't appear to support const as a way of indicating that a property can only be a single value and cannot be changed.

@womblep
Copy link

womblep commented Jun 4, 2024

This issue looks to be with this code:

      const appendType = (type: string) => {
        if (type.startsWith('null | ')) {
          propTypes.add('null');
          propTypes.add(type.substring('null | '.length));
        } else {
          propTypes.add(type);
        }
      };

If that could also have an array passed and if type is an array, check for null, then it should work

@womblep
Copy link

womblep commented Jun 4, 2024

I monkey patched that code and it allows the files to be generated. The "object" handlebars template also needs to be updated to put a "|" between multiple types.

@vosecek
Copy link

vosecek commented Aug 26, 2024

I monkey patched that code and it allows the files to be generated. The "object" handlebars template also needs to be updated to put a "|" between multiple types.

Can you provide @womblep object.handlebards updated template? Thanks.

@womblep
Copy link

womblep commented Aug 26, 2024

@vosecek sorry I dont have time to do a PR at the moment, I went down a different path to solve my problem.
Here is a quick patch I did. Hope it helps
openapi_3_1_compatibility_with_null.patch

@vosecek
Copy link

vosecek commented Aug 26, 2024

@womblep thanks, looks great.

I achieved meanwhile to working solution by modifying method collectContent(desc) operation.js file, but your result looks much better.

my solution (including skip type.startsWith in model.js) is here.

collectContent(desc) {
        const result = [];
        if (desc) {
            for (const type of Object.keys(desc)) {
                for (var i in desc[type].schema.properties) {
                    if (typeof desc[type].schema.properties[i].type === 'object') {
                        if(typeof desc[type].schema.properties[i].type.includes('null')) {
                            desc[type].schema.properties[i].type = desc[type].schema.properties[i].type.toString().replace(',null','|null');
                        }
                    }
                }
                result.push(new content_1.Content(type, desc[type], this.options, this.openApi));
            }
        }
        return result;
    }

@er1z
Copy link

er1z commented Aug 29, 2024

Any chances for this to be fixed in the upstream?

@luisfpg
Copy link
Contributor

luisfpg commented Sep 6, 2024

Sorry, I've been quite busy and don't have any time left for this project lately.
From time to time I do a push in this project, but November 2023 was the last time I could touch it.
I do have in mind the OAS 3.1 changes, but I can't promise any time frame.

@luisfpg luisfpg added the oas3.1 OpenAPI 3.1 specification support label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
oas3.1 OpenAPI 3.1 specification support
Projects
None yet
Development

No branches or pull requests

7 participants