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

Array schema values aren't marked as readonly #1102

Closed
ezequiel opened this issue Dec 6, 2023 · 2 comments · Fixed by #1103
Closed

Array schema values aren't marked as readonly #1102

ezequiel opened this issue Dec 6, 2023 · 2 comments · Fixed by #1103
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@ezequiel
Copy link
Contributor

ezequiel commented Dec 6, 2023

What are the steps to reproduce this issue?

{
  "swagger": "2.0",
  "info": {
    "title": "My API",
    "version": "1.0"
  },
  "paths": {},
  "definitions": {
    "models.ThingDescription": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string"
        }
      }
    },
    "models.Thing": {
      "type": "object",
      "properties": {
        "ThingDescriptions": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/models.ThingDescription"
          },
          "readOnly": true
        }
      }
    }
  }
}

What happens?

When an array schema has "readOnly": true set, the field value isn't marked as readonly. e.g. below, field ThingDescriptions is correctly marked as readonly, but the value ModelsThingDescription[] isn't

export type ModelsThingDescription = {
  text?: string;
};

export type ModelsThing = {
  readonly ThingDescriptions?: ModelsThingDescription[];
};

What were you expecting to happen?

ModelsThingDescription[] is marked as readonly

export type ModelsThingDescription = {
  text?: string;
};

export type ModelsThing = {
  readonly ThingDescriptions?: readonly ModelsThingDescription[];
};

What versions are you using?

Operating System: Mac OS Ventura
Package Version: latest
Browser Version: Chrome latest

@ezequiel
Copy link
Contributor Author

ezequiel commented Dec 6, 2023

My hunch is we just have to check if the schema is readOnly here, and prepend "readonly " to the value: https://github.com/anymaniax/orval/blob/8bf7cbf48709a695566b969efe2950df1a0a7546/packages/core/src/getters/array.ts#L27-L29

@melloware
Copy link
Collaborator

want me to assign to you?

@melloware melloware added the enhancement New feature or request label Dec 6, 2023
ezequiel added a commit to ezequiel/orval that referenced this issue Dec 6, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@melloware melloware added this to the 6.23.0 milestone Dec 6, 2023
melloware pushed a commit that referenced this issue Dec 6, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
* fix(core): readonly array schema value

fixes #1102

* docs(samples): format directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants