Skip to content

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

Open
@sbe-visma

Description

@sbe-visma

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-tsRelevant to the openapi-typescript library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions