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

Problem reading vendor extensions applied of properties #14327

Open
6 tasks
mwilby opened this issue Dec 26, 2022 · 0 comments
Open
6 tasks

Problem reading vendor extensions applied of properties #14327

mwilby opened this issue Dec 26, 2022 · 0 comments

Comments

@mwilby
Copy link

mwilby commented Dec 26, 2022

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

There is a bug in the reading of vendor extensions applied to properties when the property is a referenced object.

In this case the extensions are ignored. I have checked it against a variety of languages and the effect is the same across all of them, so the problem is probably in the swagger parser, but I thought it should be reported here as it manifest as a bug here, even if the source is in another tool.

openapi-generator version

I have check it in

  • 4.3.0
  • 5.3.0
  • 6.2.1

Didn't check master as there is no sign its been considered and it is probably a problem with the swagger parser.

OpenAPI declaration file content or url

To illustrate the problem consider the following schema:

test_message:
   type: object
   properties:
      primitive:
         type: integer
         x-format: u32
         x-maitred-index: 0
      in_line:
         type: object
         x-maitred-index: 1
         properties:
            id:
               description: Vehical registation ID.
               type: string
               x-maitred-index: 0
         description: in_line description
      ref_obj:
         $ref: '#/ref_obj'
         x-maitred-index: 2
         description: ref_obj external description
    
ref_obj:
   type: object
   required:
      - id
   description: ref_obj internal description
   properties:
      id:
         description: Vehical registation ID.
         type: string
         x-maitred-index: 0
Generation Details

I have tried it with

java  -cp .:-/src -DdebugModels -jar openapi-generator-cli-6.2.1.jar generate  
        -i  schema/api_def/objects_api.yaml 
        -g csharp  
        --additional-properties=library=native,serializationLibrary=jackson,java8=true 
        -t templates/csharp 
        -o log/generation.log 

and with additional properties set to

        --additional-properties=library=native,serializationLibrary=jackson 
        --additional-properties=library=native 
        --additional-properties=serializationLibrary=jackson 

as well as no additional properties.

Steps to reproduce

If you look at the relevant parameters of the JSON generated from the above schema which is passed to the mustache template, you get the following:

C#

  "importPath" : "Model.TestMessage",
  "model" : {
    "name" : "test_message",
    "vars" : [ {
      "baseName" : "primitive",
      "isPrimitiveType" : true,
      "isModel" : false,
      "vendorExtensions" : {
        "x-format" : "u32",
        "x-maitred-index" : 0,
        "x-csharp-value-type" : true,
        "x-is-value-type" : true,
        "x-emit-default-value" : false
      },
    }, {
      "baseName" : "in_line",
      "isPrimitiveType" : false,
      "isModel" : true,
      "vendorExtensions" : {
        "x-emit-default-value" : false,
        "x-maitred-index" : 1,
        "x-is-value-type" : false
      },
    }, {
      "baseName" : "ref_obj",
      "isPrimitiveType" : false,
      "isModel" : true,
      "vendorExtensions" : {
        "x-emit-default-value" : false,
        "x-is-value-type" : false
      },
    } ],
  }

Rust

    "name" : "test_message",
    "vars" : [ {
      "baseName" : "primitive",
      "isPrimitiveType" : true,
      "isModel" : false,
      "vendorExtensions" : {
        "x-format" : "u32",
        "x-maitred-index" : 0
      },
    }, {
      "baseName" : "in_line",
      "isPrimitiveType" : false,
      "isModel" : true,
      "vendorExtensions" : {
        "x-maitred-index" : 1
      },
    }, {
      "baseName" : "ref_obj",
      "isPrimitiveType" : false,
      "isModel" : true,
      "vendorExtensions" : { },
    } ],

Python Flask

  "model" : {
    "name" : "test_message",
    "vars" : [ {
      "baseName" : "primitive",
      "isPrimitiveType" : true,
      "isModel" : false,
      "vendorExtensions" : {
        "x-format" : "u32",
        "x-maitred-index" : 0
      },
    }, {
      "baseName" : "in_line",
      "isPrimitiveType" : false,
      "isModel" : true,
      "vendorExtensions" : {
        "x-maitred-index" : 1
      },
    }, {
      "baseName" : "ref_obj",
      "isPrimitiveType" : false,
      "isModel" : true,
      "vendorExtensions" : { },
    } ],
Related issues/PRs

Couldn't find any.

Suggest a fix

I have checked several other languages and it is all basically the same. I think the swagger parser, when its sees a reference it does not bother the read and/or pass back the extensions, but in the case of in-line processes it does. In the case of C# x-emit-default-value and x-is-value-type are added by the generator, so only the schema present entries are missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant