Skip to content

fix(core): decode ~0 tilde escapes in JSON Pointer refs #3413

Description

@aqeelat

Problem

getRefInfo in packages/core/src/getters/ref.ts decodes JSON Pointer path segments for $ref values, but it only handles the / escape (~1). It does not decode the tilde escape (~0).

Per RFC 6901 section 3, JSON Pointer reference tokens must decode both escape sequences:

  • ~1 becomes /
  • ~0 becomes ~

The replacement order matters. ~1 should be decoded before ~0 so escaped tokens are not decoded incorrectly.

Current behavior

A schema named My~Type must be referenced as:

{ "$ref": "#/components/schemas/My~0Type" }

Today, Orval leaves the escaped tilde in the decoded path segment. That means #/components/schemas/My~0Type is treated as if the schema name were My~0Type, instead of My~Type.

This can cause refs to resolve to the wrong name or fail to resolve when a component key contains a literal ~.

Expected behavior

getRefInfo should decode JSON Pointer escape sequences according to RFC 6901:

part.replaceAll('~1', '/').replaceAll('~0', '~')

For example:

Ref Decoded schema name
#/components/schemas/My~0Type My~Type
#/components/schemas/Path~1To~0Thing Path/To~Thing

Impact

This is a general $ref correctness issue. Specs with component names containing a literal tilde (~) can generate incorrect names or fail to resolve refs correctly.

The fix should only affect refs that contain ~0; existing refs without tilde escapes should continue to behave the same.

Suggested scope

Files likely involved:

  • packages/core/src/getters/ref.ts
  • packages/core/src/getters/ref.test.ts
  • packages/core/src/resolvers/ref.test.ts

Suggested test coverage:

  • getRefInfo decodes #/components/schemas/My~0Type to My~Type
  • getRefInfo decodes a path segment containing both ~1 and ~0
  • resolveRef resolves a schema whose component key contains a literal ~

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions