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

readOnly is not picked up from document if ref is used with enums #1938

Open
terragady opened this issue Oct 3, 2024 · 4 comments
Open

readOnly is not picked up from document if ref is used with enums #1938

terragady opened this issue Oct 3, 2024 · 4 comments
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@terragady
Copy link

terragady commented Oct 3, 2024

let's have this as an example of OpenAPI docs json:

     "ParticipantModel": {
        "required": [
          "id",
          "participantType"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "The id of the entity, mandatory when doing updates",
            "format": "uuid",
            "readOnly": true,
            "example": "a1b2c3d4-1234-5678-90ab-cdef12345678"
          },
          "participantType": {
            "$ref": "#/components/schemas/ParticipantType"
          },
     }}

where #/components/schemas/ParticipantType ref is:

     "ParticipantType": {
        "type": "string",
        "description": "The type of participant",
        "readOnly": true,
        "example": "MAIN_APPLICANT",
        "enum": [
          "MAIN_APPLICANT",
          "CO_APPLICANT"
        ]
      },

I have 2 fields where one is a string, required but readOnly and other one is enum and same reqired and should be readOnly.

but the converter converts it to not "readOnly" field like this:

    ParticipantModel: {
      readonly id: string;
      participantType: components['schemas']['ParticipantType'];
    }
    schemas: {
        ParticipantType: ParticipantType;
    }
    export enum ParticipantType {
          MAIN_APPLICANT = 'MAIN_APPLICANT',
          CO_APPLICANT = 'CO_APPLICANT',
    }

Using: "openapi-typescript": "7.4.1" with CLI and --enum flag
I think it should resolve to:

    ParticipantModel: {
      readonly id: string;
      readonly participantType: components['schemas']['ParticipantType'];
    }

?

@terragady terragady added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Oct 3, 2024
@terragady
Copy link
Author

Seems like this is an issue on all non-primitive types, not just enum.

@BrendanJM
Copy link

Possibly a duplicate here? #604

@terragady
Copy link
Author

no it is not, this one does not give readOnly property at all while issue you mentioned is about creating types without readOnly or writeOnly for usage

@sahandsn
Copy link

we need this feature. django backend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

3 participants