Skip to content

Commit

Permalink
chore: setup yarn workspace and turborepo for samples and regen…
Browse files Browse the repository at this point in the history
…erated for each sample (orval-labs#1401)

* chore: setup `yarn workspace` and `turborepo` for `samples`

* chore: add `generate-api` script to `basic` sample app

* chore: regenerate on every sample apps except `nx-fastify-react`
  • Loading branch information
soartec-lab authored May 27, 2024
1 parent a7e6a18 commit 71b6321
Show file tree
Hide file tree
Showing 14 changed files with 20,667 additions and 53 deletions.
14 changes: 9 additions & 5 deletions samples/angular-app/src/api/endpoints/pets/pets.msw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ export const getShowPetByIdResponseMock = () =>
export const getListPetsMockHandler = (
overrideResponse?:
| Pets
| ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Pets),
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<Pets> | Pets),
) => {
return http.get('*/v:version/pets', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getListPetsResponseMock(),
),
Expand All @@ -54,7 +56,7 @@ export const getCreatePetsMockHandler = () => {
return http.post('*/v:version/pets', async () => {
await delay(1000);
return new HttpResponse(null, {
status: 200,
status: 201,
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -65,15 +67,17 @@ export const getCreatePetsMockHandler = () => {
export const getShowPetByIdMockHandler = (
overrideResponse?:
| Pet
| ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Pet),
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<Pet> | Pet),
) => {
return http.get('*/v:version/pets/:petId', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getShowPetByIdResponseMock(),
),
Expand Down
3 changes: 2 additions & 1 deletion samples/angular-app/src/api/endpoints/pets/pets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ type HttpClientOptions = {

@Injectable({ providedIn: 'root' })
export class PetsService {
constructor(private http: HttpClient) {} /**
constructor(private http: HttpClient) {}
/**
* @summary List all pets
*/
listPets<TData = Pets>(params?: ListPetsParams, version: number = 1) {
Expand Down
18 changes: 11 additions & 7 deletions samples/basic/api/endpoints/petstoreFromFileSpecWithTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,17 @@ export const getShowPetByIdResponseMock = () =>
export const getListPetsMockHandler = (
overrideResponse?:
| PetsArray
| ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => PetsArray),
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<PetsArray> | PetsArray),
) => {
return http.get('*/v:version/pets', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getListPetsResponseMock(),
),
Expand All @@ -167,7 +169,7 @@ export const getCreatePetsMockHandler = () => {
return http.post('*/v:version/pets', async () => {
await delay(1000);
return new HttpResponse(null, {
status: 200,
status: 201,
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -180,15 +182,15 @@ export const getListPetsNestedArrayMockHandler = (
| PetsNestedArray
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => PetsNestedArray),
) => Promise<PetsNestedArray> | PetsNestedArray),
) => {
return http.get('*/v:version/pets-nested-array', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getListPetsNestedArrayResponseMock(),
),
Expand All @@ -205,15 +207,17 @@ export const getListPetsNestedArrayMockHandler = (
export const getShowPetByIdMockHandler = (
overrideResponse?:
| Pet
| ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Pet),
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<Pet> | Pet),
) => {
return http.get('*/v:version/pets/:petId', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getShowPetByIdResponseMock(),
),
Expand Down
1 change: 1 addition & 0 deletions samples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "",
"main": "index.html",
"scripts": {
"generate-api": "node ../../packages/orval/dist/bin/orval.js",
"example": "run-p example:*",
"example:basic": "node ../../packages/orval/dist/bin/orval.js --input ./petstore.yaml --output ./api/endpoints/petstoreFromFileSpec.ts",
"example:config": "node ../../packages/orval/dist/bin/orval.js"
Expand Down
15 changes: 15 additions & 0 deletions samples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "samples",
"version": "1.0.0",
"private": true,
"workspaces": [
"./**/*",
"!./node_modules"
],
"devDependencies": {
"turbo": "^1.13.3"
},
"scripts": {
"generate-api": "turbo run generate-api --filter=!nx-fastify-react"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ export const getShowPetByIdResponseMock = () =>
export const getListPetsMockHandler = (
overrideResponse?:
| Pets
| ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Pets),
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<Pets> | Pets),
) => {
return http.get('*/v:version/pets', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getListPetsResponseMock(),
),
Expand All @@ -66,15 +68,17 @@ export const getListPetsMockHandler = (
export const getCreatePetsMockHandler = (
overrideResponse?:
| Pet
| ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Pet),
| ((
info: Parameters<Parameters<typeof http.post>[1]>[0],
) => Promise<Pet> | Pet),
) => {
return http.post('*/v:version/pets', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getCreatePetsResponseMock(),
),
Expand All @@ -91,15 +95,17 @@ export const getCreatePetsMockHandler = (
export const getShowPetByIdMockHandler = (
overrideResponse?:
| Pet
| ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Pet),
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<Pet> | Pet),
) => {
return http.get('*/v:version/pets/:petId', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getShowPetByIdResponseMock(),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ export const getShowPetByIdResponseMock = () =>
export const getListPetsMockHandler = (
overrideResponse?:
| Pets
| ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Pets),
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<Pets> | Pets),
) => {
return http.get('*/v:version/pets', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getListPetsResponseMock(),
),
Expand All @@ -54,7 +56,7 @@ export const getCreatePetsMockHandler = () => {
return http.post('*/v:version/pets', async () => {
await delay(1000);
return new HttpResponse(null, {
status: 200,
status: 201,
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -65,15 +67,17 @@ export const getCreatePetsMockHandler = () => {
export const getShowPetByIdMockHandler = (
overrideResponse?:
| Pet
| ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Pet),
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<Pet> | Pet),
) => {
return http.get('*/v:version/pets/:petId', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getShowPetByIdResponseMock(),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ export const getShowPetByIdResponseMock = () =>
export const getListPetsMockHandler = (
overrideResponse?:
| PetsArray
| ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => PetsArray),
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<PetsArray> | PetsArray),
) => {
return http.get('*/v:version/pets', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getListPetsResponseMock(),
),
Expand All @@ -106,7 +108,7 @@ export const getCreatePetsMockHandler = () => {
return http.post('*/v:version/pets', async () => {
await delay(1000);
return new HttpResponse(null, {
status: 200,
status: 201,
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -119,15 +121,15 @@ export const getListPetsNestedArrayMockHandler = (
| PetsNestedArray
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => PetsNestedArray),
) => Promise<PetsNestedArray> | PetsNestedArray),
) => {
return http.get('*/v:version/pets-nested-array', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getListPetsNestedArrayResponseMock(),
),
Expand All @@ -144,15 +146,17 @@ export const getListPetsNestedArrayMockHandler = (
export const getShowPetByIdMockHandler = (
overrideResponse?:
| Pet
| ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Pet),
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<Pet> | Pet),
) => {
return http.get('*/v:version/pets/:petId', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getShowPetByIdResponseMock(),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ export const getShowPetByIdResponseMock = () =>
export const getListPetsMockHandler = (
overrideResponse?:
| PetsArray
| ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => PetsArray),
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<PetsArray> | PetsArray),
) => {
return http.get('*/v:version/pets', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getListPetsResponseMock(),
),
Expand All @@ -106,7 +108,7 @@ export const getCreatePetsMockHandler = () => {
return http.post('*/v:version/pets', async () => {
await delay(1000);
return new HttpResponse(null, {
status: 200,
status: 201,
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -119,15 +121,15 @@ export const getListPetsNestedArrayMockHandler = (
| PetsNestedArray
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => PetsNestedArray),
) => Promise<PetsNestedArray> | PetsNestedArray),
) => {
return http.get('*/v:version/pets-nested-array', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getListPetsNestedArrayResponseMock(),
),
Expand All @@ -144,15 +146,17 @@ export const getListPetsNestedArrayMockHandler = (
export const getShowPetByIdMockHandler = (
overrideResponse?:
| Pet
| ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Pet),
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<Pet> | Pet),
) => {
return http.get('*/v:version/pets/:petId', async (info) => {
await delay(1000);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === 'function'
? overrideResponse(info)
? await overrideResponse(info)
: overrideResponse
: getShowPetByIdResponseMock(),
),
Expand Down
Loading

0 comments on commit 71b6321

Please sign in to comment.