Skip to content

Process crashes if the schemas has an object type with a key containing a % sign #2251

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

Open
2 tasks done
sbe-visma opened this issue Apr 11, 2025 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@sbe-visma
Copy link

sbe-visma commented Apr 11, 2025

openapi-typescript version

7.6.1

Node.js version

22.12.0

OS + version

Arch Linux / Linux 6.14.1-2-cachyos

Description

Process crashes with

/home/sbe/test/test-ts-oai/node_modules/@redocly/openapi-core/lib/ref-utils.js:45
    return decodeURIComponent(fragment.replace(/~1/g, '/').replace(/~0/g, '~'));
           ^

URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at unescapePointer (/home/sbe/test/test-ts-oai/node_modules/@redocly/openapi-core/lib/ref-utils.js:45:12)
    at Array.map (<anonymous>)
    at parsePointer (/home/sbe/test/test-ts-oai/node_modules/@redocly/openapi-core/lib/ref-utils.js:60:31)
    at parseRef (/home/sbe/test/test-ts-oai/node_modules/@redocly/openapi-core/lib/ref-utils.js:56:18)
    at createRef (file:///home/sbe/test/test-ts-oai/node_modules/openapi-typescript/dist/lib/utils.js:34:26)
    at transformSchemaObjectCore (file:///home/sbe/test/test-ts-oai/node_modules/openapi-typescript/dist/transform/schema-object.js:315:31)
    at transformSchemaObjectWithComposition (file:///home/sbe/test/test-ts-oai/node_modules/openapi-typescript/dist/transform/schema-object.js:122:28)
    at transformSchemaObject (file:///home/sbe/test/test-ts-oai/node_modules/openapi-typescript/dist/transform/schema-object.js:6:18)
    at transformSchemaObjectCore (file:///home/sbe/test/test-ts-oai/node_modules/openapi-typescript/dist/transform/schema-object.js:313:23)

as it tries to convert the key "25%" to a reference. having 25% as a property name seems to only be accepted if that key resolves to a primitive, but having it be an object for example renders this problem

Reproduction

run openapi-typescript with the following schema as input

openapi: 3.0.0

info:
  title: test %keys
  version: 1.0.0

servers:
  - url: https://example.com

security:
  - BasicAuth: []

components:
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic
  schemas:
    response:
      type: object
      properties:
        id:
          type: string
        '25%':
          type: object
          properties:
            color:
              type: string
  responses:
    success:
      description: successful response
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/response"

paths:
  /api:
    get:
      operationId: postApi
      summary: Basic info
      responses:
        '200':
          $ref: "#/components/responses/success"

Expected result

codegen runs successfully and creates valid output

Required

  • My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)

Extra

If presented with a solution the maintainers want to implement, I may be willing to do the implementation

@sbe-visma sbe-visma added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Apr 11, 2025
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

1 participant