swagger-api / swagger-api/swagger-codegen

[ASPNETCORE] readOnly property $ref type is not resolved when model is generated

Open
#9,350 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

data type is not resolved properly for readOnly model properties if $ref is used

Swagger-codegen version

2.4.5

Swagger declaration file content

category property was marked as readOnly and I need to use allOf to set data type reference using $ref

  Pet:
    title: a Pet
    description: A pet for sale in the pet store
    type: object
    required:
      - name
      - photoUrls
    properties:
      id:
        type: integer
        format: int64
      category:
        readOnly: true
        allOf:
          - $ref: '#/definitions/Category'
Command line used for generation

java -jar .\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l aspnetcore -o samples\server\petstore\aspnetcore\ --additional-properties packageGuid={3C799344-F285-4669-8FD5-7ED9B795D5C5}

however this requires Pet.category to be updated in the petstore.yaml

Steps to reproduce
  • modify petstore.yaml according to Swagger declaration file content
  • run command from Command line used for generation
  • Category property in the Pet model has unresolved Object data type
Related issues/PRs
Suggest a fix/enhancement

DefaultCodegen.getSwaggerType method does not check ComposedProperty inner properties.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with DefaultCodegen.getSwaggerType and inspect how it handles ComposedProperty inner properties. Reproduce the issue by updating petstore.yaml with the readOnly category and running the provided ASP.NET Core generation command. Done means the generated Pet.category property resolves to Category instead of Object.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.