Skip to content

feat(nx-plugin): add NX Plugin with OpenAPI client generator and executor #1947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/openapi-ts-nuxt/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this file to cache builds

"$schema": "../../node_modules/turbo/schema.json",
"extends": ["//"],
"tasks": {
"build": {
"cache": true,
"dependsOn": ["^build"],
"outputs": [".nuxt/**"]
}
}
}
8 changes: 4 additions & 4 deletions examples/openapi-ts-sample/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {
Section,
} from '@radix-ui/themes';

// @ts-expect-error
import { postFoo } from './client/sdk.gen';
import { addPet } from './client/sdk.gen';

function App() {
const onClick = async () => {
postFoo({
addPet({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this file to use actual generated code, I was getting type errors how it was

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sample is meant to be a playground for local development and testing. I thought I ignored it in ESLint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe was an issue with my IDE, why not use actual code instead of adding broken imports and ignoring it with comments?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember, I was probably testing something and didn't clean it up. It's similar to the sample snapshot script except it contains a whole app with UI. The idea is to be able to test drive the output since snapshots are never actually executed. Obviously should be way more polished!

body: {
foo: [[1, 2]],
name: 'test',
photoUrls: ['test'],
},
});
};
Expand Down
29 changes: 27 additions & 2 deletions examples/openapi-ts-sample/src/client/client.gen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
// This file is auto-generated by @hey-api/openapi-ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran the code gen


import { createClient, createConfig } from '@hey-api/client-fetch';
import {
type ClientOptions as DefaultClientOptions,
type Config,
createClient,
createConfig,
} from '@hey-api/client-fetch';

import { createClientConfig } from '../hey-api';
import type { ClientOptions } from './types.gen';

export const client = createClient(createClientConfig(createConfig()));
/**
* The `createClientConfig()` function will be called on client initialization
* and the returned object will become the client's initial configuration.
*
* You may want to initialize your client this way instead of calling
* `setConfig()`. This is useful for example if you're using Next.js
* to ensure your client always has the correct values.
*/
export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> =
(
override?: Config<DefaultClientOptions & T>,
) => Config<Required<DefaultClientOptions> & T>;

export const client = createClient(
createClientConfig(
createConfig<ClientOptions>({
baseUrl: 'https://petstore3.swagger.io/api/v3',
}),
),
);
60 changes: 2 additions & 58 deletions examples/openapi-ts-sample/src/client/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,59 +38,6 @@ export const OrderSchema = {
},
} as const;

export const CustomerSchema = {
properties: {
address: {
items: {
$ref: '#/components/schemas/Address',
},
type: 'array',
xml: {
name: 'addresses',
wrapped: true,
},
},
id: {
example: 100000,
format: 'int64',
type: 'integer',
},
username: {
example: 'fehguy',
type: 'string',
},
},
type: 'object',
xml: {
name: 'customer',
},
} as const;

export const AddressSchema = {
properties: {
city: {
example: 'Palo Alto',
type: 'string',
},
state: {
example: 'CA',
type: 'string',
},
street: {
example: '437 Lytton',
type: 'string',
},
zip: {
example: 94301,
type: 'string',
},
},
type: 'object',
xml: {
name: 'address',
},
} as const;

export const CategorySchema = {
properties: {
id: {
Expand Down Expand Up @@ -130,11 +77,11 @@ export const UserSchema = {
type: 'string',
},
password: {
example: 12345,
example: '12345',
type: 'string',
},
phone: {
example: 12345,
example: '12345',
type: 'string',
},
userStatus: {
Expand Down Expand Up @@ -206,9 +153,6 @@ export const PetSchema = {
tags: {
items: {
$ref: '#/components/schemas/Tag',
xml: {
name: 'tag',
},
},
type: 'array',
xml: {
Expand Down
Loading