···2121}
22222323export class IRContext<Spec extends Record<string, any> = any> {
2424+ /**
2525+ * Configuration for parsing and generating the output. This
2626+ * is a mix of user-provided and default values.
2727+ */
2428 public config: Config;
2929+ /**
3030+ * A map of files that will be generated from `spec`.
3131+ */
2532 public files: Files;
3333+ /**
3434+ * Intermediate representation model obtained from `spec`.
3535+ */
2636 public ir: IR;
2737 public parserConfig: ParserConfig;
3838+ /**
3939+ * Resolved specification from `input`.
4040+ */
2841 public spec: Spec;
29423043 constructor({
···6275 return createdFile;
6376 }
64777878+ /**
7979+ * Returns a specific file by ID from `files`.
8080+ */
6581 public file({ id }: Pick<ContextFile, 'id'>): TypeScriptFile | undefined {
6682 return this.files[id];
6783 }
···7793 });
7894 }
79959696+ /**
9797+ * Returns a resolved reference from `spec`.
9898+ */
8099 public resolveRef<T>($ref: string) {
81100 return resolveRef<T>({
82101 $ref,
+6
packages/openapi-ts/src/ir/schema.ts
···17171818 for (const item of schema.items) {
1919 // skip nested schemas for now, handle if necessary
2020+ if (!item.type && item.items) {
2121+ uniqueItems.push(item);
2222+ continue;
2323+ }
2424+2025 if (
2626+ // no `type` might still include `$ref` or `const`
2127 !item.type ||
2228 item.type === 'boolean' ||
2329 item.type === 'null' ||
···6262 const schema = structuredClone(_schema);
63636464 if ('$ref' in schema) {
6565- // refs are encoded probably by json-schema-ref-parser, didn't investigate
6666- // further
6767- schema.$ref = decodeURIComponent(schema.$ref);
6565+ // refs using unicode characters become encoded, didn't investigate why
6666+ // but the suspicion is this comes from `@apidevtools/json-schema-ref-parser`
6767+ schema.$ref = decodeURI(schema.$ref);
6868 return schema;
6969 }
7070···151151 stripSchema({ context, schema });
152152153153 if (schema.$ref) {
154154- // refs are encoded probably by json-schema-ref-parser, didn't investigate
155155- // further
156156- schema.$ref = decodeURIComponent(schema.$ref);
154154+ // refs using unicode characters become encoded, didn't investigate why
155155+ // but the suspicion is this comes from `@apidevtools/json-schema-ref-parser`
156156+ schema.$ref = decodeURI(schema.$ref);
157157 }
158158159159 if (
+14-1
packages/openapi-ts/src/utils/ref.ts
···66 return parts.length === 3 && parts[0] === 'components';
77};
8899+/**
1010+ * Returns the component name from `$ref`.
1111+ */
1212+export const refToName = ($ref: string): string => {
1313+ const parts = refToParts($ref);
1414+ const name = parts[parts.length - 1];
1515+ // refs using unicode characters become encoded, didn't investigate why
1616+ // but the suspicion is this comes from `@apidevtools/json-schema-ref-parser`
1717+ return decodeURI(name);
1818+};
1919+920const refToParts = ($ref: string): string[] => {
1021 // Remove the leading `#` and split by `/` to traverse the object
1122 const parts = $ref.replace(/^#\//, '').split('/');
···1930 $ref: string;
2031 spec: Record<string, any>;
2132}): T => {
2222- const parts = refToParts($ref);
3333+ // refs using unicode characters become encoded, didn't investigate why
3434+ // but the suspicion is this comes from `@apidevtools/json-schema-ref-parser`
3535+ const parts = refToParts(decodeURI($ref));
23362437 let current = spec;
2538
+21
packages/openapi-ts/test/3.0.x.spec.ts
···5858 },
5959 {
6060 config: createConfig({
6161+ input: 'discriminator-all-of.yaml',
6262+ output: 'discriminator-all-of',
6363+ }),
6464+ description: 'handles discriminator with and without mapping',
6565+ },
6666+ {
6767+ config: createConfig({
6868+ input: 'discriminator-any-of.yaml',
6969+ output: 'discriminator-any-of',
7070+ }),
7171+ description: 'handles discriminator with and without mapping',
7272+ },
7373+ {
7474+ config: createConfig({
7575+ input: 'discriminator-one-of.yaml',
7676+ output: 'discriminator-one-of',
7777+ }),
7878+ description: 'handles discriminator with and without mapping',
7979+ },
8080+ {
8181+ config: createConfig({
6182 input: 'enum-escape.json',
6283 output: 'enum-escape',
6384 }),
+21
packages/openapi-ts/test/3.1.x.spec.ts
···5858 },
5959 {
6060 config: createConfig({
6161+ input: 'discriminator-all-of.yaml',
6262+ output: 'discriminator-all-of',
6363+ }),
6464+ description: 'handles discriminator with and without mapping',
6565+ },
6666+ {
6767+ config: createConfig({
6868+ input: 'discriminator-any-of.yaml',
6969+ output: 'discriminator-any-of',
7070+ }),
7171+ description: 'handles discriminator with and without mapping',
7272+ },
7373+ {
7474+ config: createConfig({
7575+ input: 'discriminator-one-of.yaml',
7676+ output: 'discriminator-one-of',
7777+ }),
7878+ description: 'handles discriminator with and without mapping',
7979+ },
8080+ {
8181+ config: createConfig({
6182 input: 'duplicate-null.json',
6283 output: 'duplicate-null',
6384 }),
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship
···425425/**
426426 * This is a model with one property with a 'one of' relationship where the options are not $ref
427427 */
428428-export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare;
428428+export type CompositionWithOneOfDiscriminator = ({
429429+ kind?: 'circle';
430430+} & ModelCircle) | ({
431431+ kind?: 'square';
432432+} & ModelSquare);
429433430434/**
431435 * This is a model with one property with a 'any of' relationship