Skip to content

Commit

Permalink
fix: accumulate discriminator mapping keys (#1305)
Browse files Browse the repository at this point in the history
* concatenate mapping keys

* lint

* refactor
  • Loading branch information
danicc097 authored Apr 12, 2024
1 parent e114594 commit 1cc9e01
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 276 deletions.
11 changes: 8 additions & 3 deletions packages/core/src/getters/discriminators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SchemasObject } from 'openapi3-ts/oas30';
import { SchemaObject, SchemasObject } from 'openapi3-ts/oas30';
import { ContextSpecs } from '../types';
import { getRefInfo } from './ref';
import { pascal } from '../utils';
Expand Down Expand Up @@ -28,12 +28,17 @@ export const resolveDiscriminators = (
if (!subTypeSchema) {
continue;
}

const property = subTypeSchema.properties?.[
propertyName
] as SchemaObject;
subTypeSchema.properties = {
...subTypeSchema.properties,
[propertyName]: {
type: 'string',
enum: [mappingKey],
enum: [
...(property.enum ?? []),
mappingKey,
],
},
};
subTypeSchema.required = [
Expand Down
64 changes: 27 additions & 37 deletions samples/basic/api/endpoints/petstoreFromFileSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
* Swagger Petstore
* OpenAPI spec version: 1.0.0
*/
import axios from 'axios'
import type {
AxiosRequestConfig,
AxiosResponse
} from 'axios'
import axios from 'axios';
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
export type CreatePetsBody = {
name: string;
tag: string;
};

export type ListPetsParams = {
/**
* How many items to return at one time (max 100)
*/
limit?: string;
/**
* How many items to return at one time (max 100)
*/
limit?: string;
};

export interface Error {
Expand Down Expand Up @@ -54,46 +51,39 @@ export interface Pet {
*/
export type Pets = Pet[];





/**
/**
* @summary List all pets
*/
export const listPets = <TData = AxiosResponse<Pets>>(
params?: ListPetsParams, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets`,{
params?: ListPetsParams,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets`, {
...options,
params: {...params, ...options?.params},}
);
}
params: { ...params, ...options?.params },
});
};

/**
* @summary Create a pet
*/
export const createPets = <TData = AxiosResponse<void>>(
createPetsBody: CreatePetsBody, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.post(
`/pets`,
createPetsBody,options
);
}
createPetsBody: CreatePetsBody,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.post(`/pets`, createPetsBody, options);
};

/**
* @summary Info for a specific pet
*/
export const showPetById = <TData = AxiosResponse<Pet>>(
petId: string, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets/${petId}`,options
);
}
petId: string,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets/${petId}`, options);
};

export type ListPetsResult = AxiosResponse<Pets>
export type CreatePetsResult = AxiosResponse<void>
export type ShowPetByIdResult = AxiosResponse<Pet>
export type ListPetsResult = AxiosResponse<Pets>;
export type CreatePetsResult = AxiosResponse<void>;
export type ShowPetByIdResult = AxiosResponse<Pet>;
64 changes: 27 additions & 37 deletions samples/basic/api/endpoints/petstoreFromFileSpecWithConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
* Swagger Petstore
* OpenAPI spec version: 1.0.0
*/
import axios from 'axios'
import type {
AxiosRequestConfig,
AxiosResponse
} from 'axios'
import axios from 'axios';
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
export type CreatePetsBody = {
name: string;
tag: string;
};

export type ListPetsParams = {
/**
* How many items to return at one time (max 100)
*/
limit?: string;
/**
* How many items to return at one time (max 100)
*/
limit?: string;
};

export interface Error {
Expand Down Expand Up @@ -54,46 +51,39 @@ export interface Pet {
*/
export type Pets = Pet[];





/**
/**
* @summary List all pets
*/
export const listPets = <TData = AxiosResponse<Pets>>(
params?: ListPetsParams, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets`,{
params?: ListPetsParams,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets`, {
...options,
params: {...params, ...options?.params},}
);
}
params: { ...params, ...options?.params },
});
};

/**
* @summary Create a pet
*/
export const createPets = <TData = AxiosResponse<void>>(
createPetsBody: CreatePetsBody, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.post(
`/pets`,
createPetsBody,options
);
}
createPetsBody: CreatePetsBody,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.post(`/pets`, createPetsBody, options);
};

/**
* @summary Info for a specific pet
*/
export const showPetById = <TData = AxiosResponse<Pet>>(
petId: string, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets/${petId}`,options
);
}
petId: string,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets/${petId}`, options);
};

export type ListPetsResult = AxiosResponse<Pets>
export type CreatePetsResult = AxiosResponse<void>
export type ShowPetByIdResult = AxiosResponse<Pet>
export type ListPetsResult = AxiosResponse<Pets>;
export type CreatePetsResult = AxiosResponse<void>;
export type ShowPetByIdResult = AxiosResponse<Pet>;
Loading

0 comments on commit 1cc9e01

Please sign in to comment.