Comments (2)
@mrlubos sorry for the delay. here's my reproducible example
package.json
{
"name": "heyapi",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"openapi": "npx @hey-api/openapi-ts",
"redocly": "redocly bundle sample.yaml --output dist/sample.yaml"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@hey-api/openapi-ts": "^0.50.1"
}
}
openapi-ts.config.mjs
import { defineConfig } from '@hey-api/openapi-ts';
export default defineConfig({
input: './dist/sample.yaml',
output: 'ts-client',
client:'@hey-api/client-fetch',
types: {
enums: 'typescript',
export: true,
},
});
dist/sample.yaml
openapi: 3.1.0
info:
title: mytest API
description: mytest customer facing API
termsOfService: https://mytest.com/terms
contact:
name: mytest
email: [email protected]
url: https://mytest.com
version: 1.0.0
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
- url: https://api.mytest.com
security:
- JWTAuth: []
- ApiKeyAuth: []
tags:
- name: products
description: products
paths:
/organizations/{org_ern}/products/search:
post:
operationId: searchOrganizationProducts
summary: Search for products
tags:
- products
parameters:
- $ref: '#/components/parameters/org_ern'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/HubSearchRequest'
responses:
'200':
description: |
Lists the products matching the search criteria
content:
application/json:
schema:
type: object
allOf:
- $ref: '#/components/schemas/PaginationResponse'
- $ref: '#/components/schemas/SortingResult'
- type: object
required:
- entries
properties:
entries:
description: |
List of products
additionalProperties:
$ref: '#/components/schemas/ResourceReference'
'400':
description: Invalid request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorMessage'
components:
securitySchemes:
JWTAuth:
type: http
scheme: bearer
bearerFormat: JWT
ApiKeyAuth:
type: apiKey
in: header
name: X-API-KEY
schemas:
ErnField:
type: string
pattern: ^[a-z]{3}:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$
description: |
External id of a resource, this is guaranteed to be unique across all the resources of an organization.
ErrorMessage:
type: object
required:
- message
- status
properties:
message:
type: string
status:
type: string
PaginationResponse:
type: object
properties:
pagination:
type: object
properties:
chunk:
type: string
prev:
type: string
next:
type: string
SortingResult:
type: object
required:
- result
properties:
result:
type: array
items:
type: string
ResourceReference:
type: object
required:
- name
- ern
properties:
ern:
$ref: '#/components/schemas/ErnField'
name:
type: string
HubSearchRequest:
type: object
properties:
category_name:
type: string
domain:
type: string
category_erns:
type: array
items:
type: string
company_name:
type: string
product_name:
type: string
compliance_framework_erns:
type: array
items:
type: string
parameters:
org_ern:
name: org_ern
in: path
required: true
schema:
$ref: '#/components/schemas/ErnField'
description: Organization's unique identifier
Now I run the command
$ npm run openapi
services.gen.ts
contains
// This file is auto-generated by @hey-api/openapi-ts
import { client, type Options } from '@hey-api/client-fetch';
import type { SearchOrganizationProductsData, SearchOrganizationProductsError, SearchOrganizationProductsResponse } from './types.gen';
/**
* Search for products
*/
export const searchOrganizationProducts = (options: Options<SearchOrganizationProductsData>) => { return (options?.client ?? client).post<SearchOrganizationProductsResponse, SearchOrganizationProductsError>({
...options,
url: '/organizations/{org_ern}/products/search'
}); };
types.gen.ts
contains
// This file is auto-generated by @hey-api/openapi-ts
/**
* External id of a resource, this is guaranteed to be unique across all the resources of an organization.
*
*/
export type ErnField = string;
export type ErrorMessage = {
message: string;
status: string;
};
export type PaginationResponse = {
pagination?: {
chunk?: string;
prev?: string;
next?: string;
};
};
export type SortingResult = {
result: Array<(string)>;
};
export type ResourceReference = {
ern: ErnField;
name: string;
};
export type HubSearchRequest = {
category_name?: string;
domain?: string;
category_erns?: Array<(string)>;
company_name?: string;
product_name?: string;
compliance_framework_erns?: Array<(string)>;
};
/**
* Organization's unique identifier
*/
export type Parameterorg_ern = ErnField;
export type SearchOrganizationProductsData = {
body: HubSearchRequest;
path: {
/**
* Organization's unique identifier
*/
org_ern: ErnField;
};
};
export type SearchOrganizationProductsResponse = PaginationResponse & SortingResult & {
/**
* List of products
*
*/
entries: unknown; /// <---- this is what my issue is all about
};
export type SearchOrganizationProductsError = ErrorMessage;
export type $OpenApiTs = {
'/organizations/{org_ern}/products/search': {
post: {
req: SearchOrganizationProductsData;
res: {
/**
* Lists the products matching the search criteria
*
*/
'200': PaginationResponse & SortingResult & {
/**
* List of products
*
*/
entries: unknown;
};
/**
* Invalid request
*/
'400': ErrorMessage;
};
};
};
};
Please note the line
export type SearchOrganizationProductsResponse = PaginationResponse & SortingResult & {
/**
* List of products
*
*/
entries: unknown; /// <---- this is what my issue is all about
};
I hope this helps.
Thank you
from openapi-ts.
@MichaelCereda which version are you on? I am unable to reproduce. Please add a reproducible example if I need to investigate further
from openapi-ts.
Related Issues (20)
- multipart/form-data with fetch client sends content-type application/json HOT 2
- Make `"auto"` the default `parseAs` option in `@hey-api/client-fetch` HOT 5
- Error with binary response HOT 8
- Wrong infered content type for excel documents HOT 13
- Transformed Date(s) in query ends up as empty string(s) HOT 3
- securitySchemes won't support GET api key authentication HOT 4
- fetch-client does not correctly handle multipart/form-data HOT 1
- Streaming HTTP query support HOT 2
- additionalProperties creates invalid key type
- Generated client-fetch services declares client locally, but it is not exported. HOT 2
- Fetch API docs don't match implementation HOT 7
- Some config options cannot be set through cli flags HOT 3
- Create explicit client interface
- Zod plugin HOT 4
- schemas.type form removes properties from schema HOT 1
- Cannot find name 'ThrowOnError' error TS2304 HOT 13
- Make `body` optional if all fields are optional
- `client-fetch` now required a `ThrowOnError` generic which breaks manually created services with `fetch-client` HOT 4
- ThrowOnError can not be set to true HOT 7
- client type error in services.gen.ts HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openapi-ts.