@publier/openapi 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -217,6 +217,16 @@ interface AsyncApiSourceOptions {
217
217
  export declare function asyncapiSource(options: AsyncApiSourceOptions): ContentSource;
218
218
  type SampleLang = 'curl' | 'javascript' | 'python' | 'go' | 'java' | 'csharp';
219
219
  export declare function generateCodeSample(method: HttpMethod, path: string, operation: OpenApiOperation, lang: SampleLang, baseUrl: string, spec?: OpenApiSpec): string;
220
+ /**
221
+ * Build the full `(lang, label, code)` triple list the Rust renderer
222
+ * expects, in the canonical LANGUAGES order. Honors x-codeSamples
223
+ * overrides first, then falls back to auto-generation.
224
+ */
225
+ export declare function buildCodeSamples(method: HttpMethod, path: string, operation: OpenApiOperation, baseUrl: string, spec?: OpenApiSpec): {
226
+ lang: SampleLang;
227
+ label: string;
228
+ code: string;
229
+ }[];
220
230
  interface APIReferenceProps {
221
231
  method: HttpMethod;
222
232
  path: string;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{asyncapiSourceBuild as e,openapiExtractEndpoints as t,openapiNavigationBuild as n,openapiSourceBuild as r}from"@publier/native";import{HTTPSnippet as i}from"@readme/httpsnippet";import a from"@readme/oas-to-har";import o from"oas";import s from"openapi-sampler";function c(t){let{spec:n,baseUrl:r=``}=t,{pages:i,tree:a}=JSON.parse(e(JSON.stringify(n),r)),o=new Map(i.map(e=>[e.slug.join(`/`),e]));return{async getPage(e){return o.get(e.join(`/`))},async getPages(){return i},async getPageTree(){return a},async generateParams(){return i.map(e=>({slug:e.slug}))}}}function l(e){return s.sample(e)}function u(e,t=`application/json`){let n=e[t]??Object.values(e)[0];if(!n)return;if(n.example!==void 0)return n.example;let r=Object.values(n.examples??{}).find(e=>e.value!==void 0);return r?r.value:n.schema?l(n.schema):void 0}function d(e){return JSON.stringify(e,null,2)}function f(e,t=`application/json`){let n=u(e,t);return n===void 0?void 0:d(n)}const p={curl:[`shell`,`curl`],javascript:[`javascript`,`fetch`],python:[`python`,`requests`],go:[`go`,`native`],java:[`java`,`nethttp`],csharp:[`csharp`,`httpclient`]};function m(e,t){let n=e.getDefinition().components?.securitySchemes??{},r={};for(let e of Object.keys(t[0]??{})){let t=n[e];t?.type===`http`&&t.scheme?.toLowerCase()===`basic`?r[e]={user:`<username>`,pass:`<password>`}:t?.type===`apiKey`?r[e]=`<api-key>`:t&&(r[e]=`<token>`)}return r}function h(e,t,n,r,i){let s={openapi:`3.0.0`,info:{title:`API`,version:`1`},...i,servers:[{url:r}],paths:{...i?.paths,[t]:{...i?.paths?.[t],[e]:n}}},c=new o(s),l=c.operation(t,e),d={path:{},query:{},header:{},cookie:{}};for(let[,e]of t.matchAll(/\{([^}]+)\}/g))e&&(d.path[e]=`{${e}}`);for(let e of l.getParameters()){let t=d[e.in];t&&e.in!==`path`&&(t[e.name]=`<value>`)}if(l.hasRequestBody()){let e=l.schema.requestBody,t=l.getContentType(),n=u(e?.content??{},t);l.isFormUrlEncoded()||l.isMultipart()?d.formData=n??{}:n!==void 0&&(d.body=n)}return a(c,l,d,m(c,l.getSecurity())).log.entries[0].request}function g(e){return e.replace(/%(?:25)?(3C|3E|7B|7D)/gi,(e,t)=>String.fromCharCode(Number.parseInt(t,16)))}function _(e,t){let[n,r]=p[t],a=new i(e).convert(n,r),o=Array.isArray(a)?a.find(e=>typeof e==`string`):a;return g(typeof o==`string`?o:``)}function v(e,t,n,r,i,a){return p[r]?_(h(e,t,n,i,a),r):``}const y=[`get`,`post`,`put`,`delete`,`patch`,`head`,`options`];function b(e,n={}){let{mergePathParameters:r=!1,includeWebhooks:i=!0}=n;return JSON.parse(t(JSON.stringify(e),r,i))}function x(e,t={}){let{groupBy:r=`tag`,slugPrefix:i,excludeDeprecated:a=!1,includeWebhooks:o=!0}=t;return JSON.parse(n(JSON.stringify(e),r,i??null,a,o))}function S(e){let{spec:t,baseUrl:n=``}=e,{pages:i,tree:a}=JSON.parse(r(JSON.stringify(t),n)),o=new Map(i.map(e=>[e.slug.join(`/`),e]));return{async getPage(e){return o.get(e.join(`/`))},async getPages(){return i},async getPageTree(){return a},async generateParams(){return i.map(e=>({slug:e.slug}))}}}export{y as HTTP_METHODS,c as asyncapiSource,x as buildNavigation,b as extractEndpoints,d as formatJson,v as generateCodeSample,l as generateExampleFromSchema,f as getMediaTypeExample,S as openapiSource};
1
+ import{asyncapiSourceBuild as e,openapiExtractEndpoints as t,openapiNavigationBuild as n,openapiSourceBuild as r}from"@publier/native";import{HTTPSnippet as i}from"@readme/httpsnippet";import a from"@readme/oas-to-har";import o from"oas";import*as s from"openapi-sampler";function c(t){let{spec:n,baseUrl:r=``}=t,{pages:i,tree:a}=JSON.parse(e(JSON.stringify(n),r)),o=new Map(i.map(e=>[e.slug.join(`/`),e]));return{async getPage(e){return o.get(e.join(`/`))},async getPages(){return i},async getPageTree(){return a},async generateParams(){return i.map(e=>({slug:e.slug}))}}}const l=s.sample??s.default.sample;function u(e){return l(e)}function d(e,t=`application/json`){let n=e[t]??Object.values(e)[0];if(!n)return;if(n.example!==void 0)return n.example;let r=Object.values(n.examples??{}).find(e=>e.value!==void 0);return r?r.value:n.schema?u(n.schema):void 0}function f(e){return JSON.stringify(e,null,2)}function p(e,t=`application/json`){let n=d(e,t);return n===void 0?void 0:f(n)}const m=[`curl`,`javascript`,`python`,`go`,`java`,`csharp`],h={curl:`cURL`,javascript:`JavaScript`,python:`Python`,go:`Go`,java:`Java`,csharp:`C#`},g={curl:[`shell`,`curl`],javascript:[`javascript`,`fetch`],python:[`python`,`requests`],go:[`go`,`native`],java:[`java`,`nethttp`],csharp:[`csharp`,`httpclient`]},_={curl:`curl`,javascript:`javascript`,js:`javascript`,python:`python`,py:`python`,go:`go`,golang:`go`,java:`java`,csharp:`csharp`,"c#":`csharp`,cs:`csharp`};function v(e,t){let n=e.getDefinition().components?.securitySchemes??{},r={};for(let e of Object.keys(t[0]??{})){let t=n[e];t?.type===`http`&&t.scheme?.toLowerCase()===`basic`?r[e]={user:`<username>`,pass:`<password>`}:t?.type===`apiKey`?r[e]=`<api-key>`:t&&(r[e]=`<token>`)}return r}function y(e,t,n,r,i){let s={openapi:`3.0.0`,info:{title:`API`,version:`1`},...i,servers:[{url:r}],paths:{...i?.paths,[t]:{...i?.paths?.[t],[e]:n}}},c=new o(s),l=c.operation(t,e),u={path:{},query:{},header:{},cookie:{}};for(let[,e]of t.matchAll(/\{([^}]+)\}/g))e&&(u.path[e]=`{${e}}`);for(let e of l.getParameters()){let t=u[e.in];t&&e.in!==`path`&&(t[e.name]=`<value>`)}if(l.hasRequestBody()){let e=l.schema.requestBody,t=l.getContentType(),n=d(e?.content??{},t);l.isFormUrlEncoded()||l.isMultipart()?u.formData=n??{}:n!==void 0&&(u.body=n)}return a(c,l,u,v(c,l.getSecurity())).log.entries[0].request}function b(e){return e.replace(/%(?:25)?(3C|3E|7B|7D)/gi,(e,t)=>String.fromCharCode(Number.parseInt(t,16)))}function x(e,t){let[n,r]=g[t],a=new i(e).convert(n,r),o=Array.isArray(a)?a.find(e=>typeof e==`string`):a;return b(typeof o==`string`?o:``)}function S(e,t,n,r,i,a){return g[r]?x(y(e,t,n,i,a),r):``}function C(e){let t=/* @__PURE__ */ new Map;for(let{lang:n,source:r}of e){let e=_[n.trim().toLowerCase()];e&&t.set(e,r)}return t}function w(e,t,n,r,i){let a=C(n[`x-codeSamples`]??[]),o=m.some(e=>!a.has(e))?y(e,t,n,r,i):void 0;return m.map(e=>({lang:e,label:h[e],code:a.get(e)??(o?x(o,e):``)}))}const T=[`get`,`post`,`put`,`delete`,`patch`,`head`,`options`];function E(e,n={}){let{mergePathParameters:r=!1,includeWebhooks:i=!0}=n;return JSON.parse(t(JSON.stringify(e),r,i))}function D(e,t={}){let{groupBy:r=`tag`,slugPrefix:i,excludeDeprecated:a=!1,includeWebhooks:o=!0}=t;return JSON.parse(n(JSON.stringify(e),r,i??null,a,o))}function O(e){let{spec:t,baseUrl:n=``}=e,{pages:i,tree:a}=JSON.parse(r(JSON.stringify(t),n)),o=new Map(i.map(e=>[e.slug.join(`/`),e]));return{async getPage(e){return o.get(e.join(`/`))},async getPages(){return i},async getPageTree(){return a},async generateParams(){return i.map(e=>({slug:e.slug}))}}}export{T as HTTP_METHODS,c as asyncapiSource,w as buildCodeSamples,D as buildNavigation,E as extractEndpoints,f as formatJson,S as generateCodeSample,u as generateExampleFromSchema,p as getMediaTypeExample,O as openapiSource};
package/dist/parser.d.mts CHANGED
@@ -144,8 +144,12 @@ interface OpenApiCodeSample {
144
144
  /**
145
145
  * @param input File path, URL, or the JSON/YAML text of a spec, or a parsed
146
146
  * spec object. Relative external `$ref`s resolve against a path or URL input.
147
+ * @param options.onRead Called with each local file the parser reads (the spec
148
+ * and the files it `$ref`s), so a dev server can watch them.
147
149
  * @throws with the parser's validation messages when the document is not a
148
150
  * valid OpenAPI/Swagger document.
149
151
  */
150
- export declare function parseOpenApiSpec(input: string | object): Promise<OpenApiSpec>;
152
+ export declare function parseOpenApiSpec(input: string | object, options?: {
153
+ onRead?: (file: string) => void;
154
+ }): Promise<OpenApiSpec>;
151
155
  export {};
package/dist/parser.mjs CHANGED
@@ -1 +1 @@
1
- import{bundle as e}from"@scalar/json-magic/bundle";import{fetchUrls as t,parseJson as n,parseYaml as r}from"@scalar/json-magic/bundle/plugins/browser";import{readFiles as i}from"@scalar/json-magic/bundle/plugins/node";import{dereference as a,validate as o}from"@scalar/openapi-parser";import{upgradeFromTwoToThree as s}from"@scalar/openapi-upgrader/2.0-to-3.0";function c(e,t,n){if(typeof e!=`object`||!e)return e;let r=t.get(e);if(r!==void 0){if(n.has(r))return{$ref:r};n.add(r)}let i=Array.isArray(e)?e.map(e=>c(e,t,n)):Object.fromEntries(Object.entries(e).map(([e,r])=>[e,c(r,t,n)]));return r!==void 0&&n.delete(r),i}async function l(l){let u=await e(l,{plugins:[i(),t(),r(),n()],treeShake:!1}),d=typeof u.swagger==`string`?s(u):u,f=await o(d);if(!f.valid){let e=f.errors.map(e=>e.message).join(`; `);throw Error(`Invalid OpenAPI spec: ${e}`)}let p=/* @__PURE__ */ new Map,{schema:m,errors:h}=a(d,{onDereference:({schema:e,ref:t})=>{p.set(e,t)}});if(h?.length)throw Error(`Invalid OpenAPI spec: ${h.map(e=>e.message).join(`; `)}`);return c(m,p,/* @__PURE__ */ new Set)}export{l as parseOpenApiSpec};
1
+ import{bundle as e}from"@scalar/json-magic/bundle";import{fetchUrls as t,parseJson as n,parseYaml as r}from"@scalar/json-magic/bundle/plugins/browser";import{readFiles as i}from"@scalar/json-magic/bundle/plugins/node";import{dereference as a,validate as o}from"@scalar/openapi-parser";import{upgradeFromTwoToThree as s}from"@scalar/openapi-upgrader/2.0-to-3.0";function c(e,t,n){if(typeof e!=`object`||!e)return e;let r=t.get(e);if(r!==void 0){if(n.has(r))return{$ref:r};n.add(r)}let i=Array.isArray(e)?e.map(e=>c(e,t,n)):Object.fromEntries(Object.entries(e).map(([e,r])=>[e,c(r,t,n)]));return r!==void 0&&n.delete(r),i}async function l(l,u={}){let d=i(),f={...d,exec:e=>(u.onRead?.(e),d.exec(e))},p=await e(l,{plugins:[f,t(),r(),n()],treeShake:!1}),m=typeof p.swagger==`string`?s(p):p,h=await o(m);if(!h.valid){let e=h.errors.map(e=>e.message).join(`; `);throw Error(`Invalid OpenAPI spec: ${e}`)}let g=/* @__PURE__ */ new Map,{schema:_,errors:v}=a(m,{onDereference:({schema:e,ref:t})=>{g.set(e,t)}});if(v?.length)throw Error(`Invalid OpenAPI spec: ${v.map(e=>e.message).join(`; `)}`);return c(_,g,/* @__PURE__ */ new Set)}export{l as parseOpenApiSpec};
package/dist/server.mjs CHANGED
@@ -1 +1 @@
1
- import{openapiExtractEndpoints as e,openapiMergeSpecs as t,openapiNavigationBuild as n}from"@publier/native";import{bundle as r}from"@scalar/json-magic/bundle";import{fetchUrls as i,parseJson as a,parseYaml as o}from"@scalar/json-magic/bundle/plugins/browser";import{readFiles as s}from"@scalar/json-magic/bundle/plugins/node";import{dereference as c,validate as l}from"@scalar/openapi-parser";import{upgradeFromTwoToThree as u}from"@scalar/openapi-upgrader/2.0-to-3.0";const d=[`get`,`post`,`put`,`delete`,`patch`,`head`,`options`];function f(t,n={}){let{mergePathParameters:r=!1,includeWebhooks:i=!0}=n;return JSON.parse(e(JSON.stringify(t),r,i))}function p(e,t={}){let{groupBy:r=`tag`,slugPrefix:i,excludeDeprecated:a=!1,includeWebhooks:o=!0}=t;return JSON.parse(n(JSON.stringify(e),r,i??null,a,o))}function m(e,t,n){if(typeof e!=`object`||!e)return e;let r=t.get(e);if(r!==void 0){if(n.has(r))return{$ref:r};n.add(r)}let i=Array.isArray(e)?e.map(e=>m(e,t,n)):Object.fromEntries(Object.entries(e).map(([e,r])=>[e,m(r,t,n)]));return r!==void 0&&n.delete(r),i}async function h(e){let t=await r(e,{plugins:[s(),i(),o(),a()],treeShake:!1}),n=typeof t.swagger==`string`?u(t):t,d=await l(n);if(!d.valid){let e=d.errors.map(e=>e.message).join(`; `);throw Error(`Invalid OpenAPI spec: ${e}`)}let f=/* @__PURE__ */ new Map,{schema:p,errors:h}=c(n,{onDereference:({schema:e,ref:t})=>{f.set(e,t)}});if(h?.length)throw Error(`Invalid OpenAPI spec: ${h.map(e=>e.message).join(`; `)}`);return m(p,f,/* @__PURE__ */ new Set)}function g(e){let n=null;async function r(){if(n&&!e.disableCache)return n;let r=[];for(let t of e.input)typeof t==`string`?r.push(await h(t)):r.push(t);if(r.length===0)throw Error(`No OpenAPI specs provided`);return r.length===1?(n=r[0],n):(n=JSON.parse(t(JSON.stringify(r))),n)}return{getSpec:r,async getOperation(e){let t=await r();for(let[n,r]of Object.entries(t.paths))for(let t of d){let i=r[t];if(i?.operationId===e)return{method:t,path:n,operation:i}}},async getOperationByPath(e,t){let n=(await r()).paths[e]?.[t];return n?{method:t,path:e,operation:n}:void 0},async getOperationsByTag(e){return f(await r(),{mergePathParameters:!0}).filter(t=>t.operation.tags?.includes(e)).map(({method:e,path:t,operation:n})=>({method:e,path:t,operation:n}))},async getEndpoints(){return f(await r(),{mergePathParameters:!0})},async getNavigation(e){return p(await r(),e)}}}export{g as createOpenAPI};
1
+ import{openapiExtractEndpoints as e,openapiMergeSpecs as t,openapiNavigationBuild as n}from"@publier/native";import{bundle as r}from"@scalar/json-magic/bundle";import{fetchUrls as i,parseJson as a,parseYaml as o}from"@scalar/json-magic/bundle/plugins/browser";import{readFiles as s}from"@scalar/json-magic/bundle/plugins/node";import{dereference as c,validate as l}from"@scalar/openapi-parser";import{upgradeFromTwoToThree as u}from"@scalar/openapi-upgrader/2.0-to-3.0";const d=[`get`,`post`,`put`,`delete`,`patch`,`head`,`options`];function f(t,n={}){let{mergePathParameters:r=!1,includeWebhooks:i=!0}=n;return JSON.parse(e(JSON.stringify(t),r,i))}function p(e,t={}){let{groupBy:r=`tag`,slugPrefix:i,excludeDeprecated:a=!1,includeWebhooks:o=!0}=t;return JSON.parse(n(JSON.stringify(e),r,i??null,a,o))}function m(e,t,n){if(typeof e!=`object`||!e)return e;let r=t.get(e);if(r!==void 0){if(n.has(r))return{$ref:r};n.add(r)}let i=Array.isArray(e)?e.map(e=>m(e,t,n)):Object.fromEntries(Object.entries(e).map(([e,r])=>[e,m(r,t,n)]));return r!==void 0&&n.delete(r),i}async function h(e,t={}){let n=s(),d={...n,exec:e=>(t.onRead?.(e),n.exec(e))},f=await r(e,{plugins:[d,i(),o(),a()],treeShake:!1}),p=typeof f.swagger==`string`?u(f):f,h=await l(p);if(!h.valid){let e=h.errors.map(e=>e.message).join(`; `);throw Error(`Invalid OpenAPI spec: ${e}`)}let g=/* @__PURE__ */ new Map,{schema:_,errors:v}=c(p,{onDereference:({schema:e,ref:t})=>{g.set(e,t)}});if(v?.length)throw Error(`Invalid OpenAPI spec: ${v.map(e=>e.message).join(`; `)}`);return m(_,g,/* @__PURE__ */ new Set)}function g(e){let n=null;async function r(){if(n&&!e.disableCache)return n;let r=[];for(let t of e.input)typeof t==`string`?r.push(await h(t)):r.push(t);if(r.length===0)throw Error(`No OpenAPI specs provided`);return r.length===1?(n=r[0],n):(n=JSON.parse(t(JSON.stringify(r))),n)}return{getSpec:r,async getOperation(e){let t=await r();for(let[n,r]of Object.entries(t.paths))for(let t of d){let i=r[t];if(i?.operationId===e)return{method:t,path:n,operation:i}}},async getOperationByPath(e,t){let n=(await r()).paths[e]?.[t];return n?{method:t,path:e,operation:n}:void 0},async getOperationsByTag(e){return f(await r(),{mergePathParameters:!0}).filter(t=>t.operation.tags?.includes(e)).map(({method:e,path:t,operation:n})=>({method:e,path:t,operation:n}))},async getEndpoints(){return f(await r(),{mergePathParameters:!0})},async getNavigation(e){return p(await r(),e)}}}export{g as createOpenAPI};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@publier/openapi",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "files": [
@@ -8,6 +8,8 @@
8
8
  "src/components/**/*.astro",
9
9
  "src/components/**/*.ts",
10
10
  "src/components/props.ts",
11
+ "src/types.ts",
12
+ "src/async-types.ts",
11
13
  "!src/**/__tests__/**",
12
14
  "!src/**/*.test.ts"
13
15
  ],
@@ -45,7 +47,7 @@
45
47
  "access": "public"
46
48
  },
47
49
  "dependencies": {
48
- "@publier/native": "0.20.0",
50
+ "@publier/native": "0.22.0",
49
51
  "@readme/httpsnippet": "^11.4.1",
50
52
  "@readme/oas-to-har": "^39.0.1",
51
53
  "@scalar/json-magic": "^0.19.1",
@@ -0,0 +1,59 @@
1
+ import type { OpenApiSchema } from './types.ts';
2
+
3
+ export interface AsyncApiSpec {
4
+ asyncapi: string;
5
+ info: { title: string; description?: string; version: string };
6
+ servers?: Record<string, AsyncApiServer>;
7
+ channels?: Record<string, AsyncApiChannel>;
8
+ operations?: Record<string, AsyncApiOperation>;
9
+ components?: AsyncApiComponents;
10
+ }
11
+
12
+ export interface AsyncApiServer {
13
+ host: string;
14
+ protocol: string;
15
+ pathname?: string;
16
+ description?: string;
17
+ tags?: { name: string; description?: string }[];
18
+ }
19
+
20
+ export interface AsyncApiChannel {
21
+ address?: string;
22
+ description?: string;
23
+ messages?: Record<string, AsyncApiMessage | { $ref: string }>;
24
+ parameters?: Record<string, AsyncApiParameter>;
25
+ tags?: { name: string; description?: string }[];
26
+ }
27
+
28
+ export interface AsyncApiOperation {
29
+ action: 'send' | 'receive';
30
+ channel: { $ref: string };
31
+ summary?: string;
32
+ description?: string;
33
+ messages?: ({ $ref: string } | AsyncApiMessage)[];
34
+ tags?: { name: string; description?: string }[];
35
+ }
36
+
37
+ export interface AsyncApiMessage {
38
+ name?: string;
39
+ title?: string;
40
+ summary?: string;
41
+ description?: string;
42
+ contentType?: string;
43
+ payload?: OpenApiSchema;
44
+ headers?: OpenApiSchema;
45
+ tags?: { name: string; description?: string }[];
46
+ }
47
+
48
+ export interface AsyncApiParameter {
49
+ description?: string;
50
+ default?: string;
51
+ enum?: string[];
52
+ }
53
+
54
+ export interface AsyncApiComponents {
55
+ schemas?: Record<string, OpenApiSchema>;
56
+ messages?: Record<string, AsyncApiMessage>;
57
+ channels?: Record<string, AsyncApiChannel>;
58
+ operations?: Record<string, AsyncApiOperation>;
59
+ }
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  import { openapiRenderCodeSamples } from '@publier/native';
3
- import { buildCodeSamples } from '../code-sample-generators.ts';
3
+ import { buildCodeSamples } from '@publier/openapi';
4
4
  import type { CodeSamplesProps } from './props.ts';
5
5
  type Props = CodeSamplesProps;
6
6
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  import { openapiRenderRequestExample } from '@publier/native';
3
- import { getMediaTypeExample } from '../example-utils.ts';
3
+ import { getMediaTypeExample } from '@publier/openapi';
4
4
  import type { RequestExampleProps } from './props.ts';
5
5
  type Props = RequestExampleProps;
6
6
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  import { openapiRenderResponseExample } from '@publier/native';
3
- import { getMediaTypeExample } from '../example-utils.ts';
3
+ import { getMediaTypeExample } from '@publier/openapi';
4
4
  import type { ResponseExampleProps } from './props.ts';
5
5
  type Props = ResponseExampleProps;
6
6
 
package/src/types.ts ADDED
@@ -0,0 +1,140 @@
1
+ export interface OpenApiSpec {
2
+ openapi: string;
3
+ info: OpenApiInfo;
4
+ servers?: OpenApiServer[];
5
+ paths: Record<string, OpenApiPathItem>;
6
+ /**
7
+ * OpenAPI 3.1 webhooks — server-to-client push endpoints, keyed by name.
8
+ * Shape-identical to path items but not part of the HTTP routing table.
9
+ */
10
+ webhooks?: Record<string, OpenApiPathItem>;
11
+ components?: OpenApiComponents;
12
+ security?: Record<string, string[]>[];
13
+ tags?: OpenApiTag[];
14
+ }
15
+
16
+ export interface OpenApiInfo {
17
+ title: string;
18
+ description?: string;
19
+ version: string;
20
+ }
21
+
22
+ export interface OpenApiServer {
23
+ url: string;
24
+ description?: string;
25
+ }
26
+
27
+ export interface OpenApiPathItem {
28
+ get?: OpenApiOperation;
29
+ post?: OpenApiOperation;
30
+ put?: OpenApiOperation;
31
+ delete?: OpenApiOperation;
32
+ patch?: OpenApiOperation;
33
+ head?: OpenApiOperation;
34
+ options?: OpenApiOperation;
35
+ summary?: string;
36
+ description?: string;
37
+ parameters?: OpenApiParameter[];
38
+ }
39
+
40
+ export interface OpenApiOperation {
41
+ operationId?: string;
42
+ summary?: string;
43
+ description?: string;
44
+ tags?: string[];
45
+ parameters?: OpenApiParameter[];
46
+ requestBody?: OpenApiRequestBody;
47
+ responses: Record<string, OpenApiResponse>;
48
+ /**
49
+ * OpenAPI 3.0+ callbacks — out-of-band requests the service will make in
50
+ * response to this operation.
51
+ */
52
+ callbacks?: Record<string, Record<string, OpenApiPathItem>>;
53
+ security?: Record<string, string[]>[];
54
+ deprecated?: boolean;
55
+ 'x-codeSamples'?: OpenApiCodeSample[];
56
+ }
57
+
58
+ export interface OpenApiParameter {
59
+ name: string;
60
+ in: 'path' | 'query' | 'header' | 'cookie';
61
+ description?: string;
62
+ required?: boolean;
63
+ schema?: OpenApiSchema;
64
+ deprecated?: boolean;
65
+ }
66
+
67
+ export interface OpenApiRequestBody {
68
+ description?: string;
69
+ required?: boolean;
70
+ content: Record<string, OpenApiMediaType>;
71
+ }
72
+
73
+ export interface OpenApiResponse {
74
+ description: string;
75
+ content?: Record<string, OpenApiMediaType>;
76
+ headers?: Record<string, { description?: string; schema?: OpenApiSchema }>;
77
+ }
78
+
79
+ export interface OpenApiMediaType {
80
+ schema?: OpenApiSchema;
81
+ example?: unknown;
82
+ examples?: Record<string, { value: unknown; summary?: string }>;
83
+ }
84
+
85
+ export interface OpenApiSchema {
86
+ type?: string;
87
+ format?: string;
88
+ description?: string;
89
+ properties?: Record<string, OpenApiSchema>;
90
+ items?: OpenApiSchema;
91
+ required?: string[];
92
+ enum?: unknown[];
93
+ default?: unknown;
94
+ oneOf?: OpenApiSchema[];
95
+ anyOf?: OpenApiSchema[];
96
+ allOf?: OpenApiSchema[];
97
+ $ref?: string;
98
+ nullable?: boolean;
99
+ readOnly?: boolean;
100
+ writeOnly?: boolean;
101
+ deprecated?: boolean;
102
+ example?: unknown;
103
+ title?: string;
104
+ minimum?: number;
105
+ maximum?: number;
106
+ pattern?: string;
107
+ minLength?: number;
108
+ maxLength?: number;
109
+ additionalProperties?: boolean | OpenApiSchema;
110
+ }
111
+
112
+ export interface OpenApiComponents {
113
+ schemas?: Record<string, OpenApiSchema>;
114
+ parameters?: Record<string, OpenApiParameter>;
115
+ responses?: Record<string, OpenApiResponse>;
116
+ requestBodies?: Record<string, OpenApiRequestBody>;
117
+ securitySchemes?: Record<string, OpenApiSecurityScheme>;
118
+ }
119
+
120
+ export interface OpenApiSecurityScheme {
121
+ type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
122
+ description?: string;
123
+ name?: string;
124
+ in?: 'query' | 'header' | 'cookie';
125
+ scheme?: string;
126
+ bearerFormat?: string;
127
+ }
128
+
129
+ export interface OpenApiTag {
130
+ name: string;
131
+ description?: string;
132
+ }
133
+
134
+ export interface OpenApiCodeSample {
135
+ lang: string;
136
+ label?: string;
137
+ source: string;
138
+ }
139
+
140
+ export type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'head' | 'options';