Skip to content
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

Bump omicron version #237

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
handle array response even though we shouldn't have them
  • Loading branch information
david-crespo committed Apr 5, 2024
commit 4e27c28f0768677f71da45bffe47253ed365989a
8 changes: 4 additions & 4 deletions client/Api.ts
Original file line number Diff line number Diff line change
@@ -6221,7 +6221,7 @@ export class Api extends HttpClient {
* Get BFD status
*/
networkingBfdStatus: (_: EmptyObj, params: FetchParams = {}) => {
return this.request<void>({
return this.request<BfdStatus[]>({
path: `/v1/system/networking/bfd-status`,
method: "GET",
...params,
@@ -6276,7 +6276,7 @@ export class Api extends HttpClient {
{ query }: { query?: NetworkingBgpAnnounceSetListQueryParams },
params: FetchParams = {}
) => {
return this.request<void>({
return this.request<BgpAnnouncement[]>({
path: `/v1/system/networking/bgp-announce`,
method: "GET",
query,
@@ -6318,7 +6318,7 @@ export class Api extends HttpClient {
{ query }: { query?: NetworkingBgpImportedRoutesIpv4QueryParams },
params: FetchParams = {}
) => {
return this.request<void>({
return this.request<BgpImportedRouteIpv4[]>({
path: `/v1/system/networking/bgp-routes-ipv4`,
method: "GET",
query,
@@ -6329,7 +6329,7 @@ export class Api extends HttpClient {
* Get BGP peer status
*/
networkingBgpStatus: (_: EmptyObj, params: FetchParams = {}) => {
return this.request<void>({
return this.request<BgpPeerStatus[]>({
path: `/v1/system/networking/bgp-status`,
method: "GET",
...params,
8 changes: 4 additions & 4 deletions client/msw-handlers.ts
Original file line number Diff line number Diff line change
@@ -885,7 +885,7 @@ export interface MSWHandlers {
networkingBfdStatus: (params: {
req: Request;
cookies: Record<string, string>;
}) => Promisable<StatusCode>;
}) => Promisable<HandlerResult<Api.BfdStatus[]>>;
/** `GET /v1/system/networking/bgp` */
networkingBgpConfigList: (params: {
query: Api.NetworkingBgpConfigListQueryParams;
@@ -909,7 +909,7 @@ export interface MSWHandlers {
query: Api.NetworkingBgpAnnounceSetListQueryParams;
req: Request;
cookies: Record<string, string>;
}) => Promisable<StatusCode>;
}) => Promisable<HandlerResult<Api.BgpAnnouncement[]>>;
/** `POST /v1/system/networking/bgp-announce` */
networkingBgpAnnounceSetCreate: (params: {
body: Json<Api.BgpAnnounceSetCreate>;
@@ -927,12 +927,12 @@ export interface MSWHandlers {
query: Api.NetworkingBgpImportedRoutesIpv4QueryParams;
req: Request;
cookies: Record<string, string>;
}) => Promisable<StatusCode>;
}) => Promisable<HandlerResult<Api.BgpImportedRouteIpv4[]>>;
/** `GET /v1/system/networking/bgp-status` */
networkingBgpStatus: (params: {
req: Request;
cookies: Record<string, string>;
}) => Promisable<StatusCode>;
}) => Promisable<HandlerResult<Api.BgpPeerStatus[]>>;
/** `GET /v1/system/networking/loopback-address` */
networkingLoopbackAddressList: (params: {
query: Api.NetworkingLoopbackAddressListQueryParams;
11 changes: 3 additions & 8 deletions generator/client/api.ts
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ import {
} from "../util";
import { initIO } from "../io";
import type { Schema } from "../schema/base";
import { refToSchemaName } from "../schema/base";
import {
contentRef,
docComment,
@@ -226,19 +225,15 @@ export function generateApi(spec: OpenAPIV3.Document, destDir: string) {
(p) => "in" in p && p.in === "query"
) as OpenAPIV3.ParameterObject[];

const bodyTypeRef = contentRef(conf.requestBody);
const bodyType = bodyTypeRef ? refToSchemaName(bodyTypeRef) : null;
const bodyType = contentRef(conf.requestBody);

const successResponse =
conf.responses["200"] ||
conf.responses["201"] ||
conf.responses["202"] ||
conf.responses["204"];

const successTypeRef = contentRef(successResponse);
const successType = successTypeRef
? refToSchemaName(successTypeRef)
: "void";
const successType = contentRef(successResponse);

docComment(conf.summary || conf.description, schemaNames, io);

@@ -270,7 +265,7 @@ export function generateApi(spec: OpenAPIV3.Document, destDir: string) {
}

w(`params: FetchParams = {}) => {
return this.request<${successType}>({
return this.request<${successType || "void"}>({
path: ${pathToTemplateStr(path)},
method: "${method.toUpperCase()}",`);
if (bodyType) {
28 changes: 20 additions & 8 deletions generator/client/base.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
import type { OpenAPIV3 } from "openapi-types";
import { topologicalSort } from "../util";
import type { IO } from "../io";
import type { Schema } from "../schema/base";
import { refToSchemaName, type Schema } from "../schema/base";
import { OpenAPIV3 as O } from "openapi-types";
const HttpMethods = O.HttpMethods;

@@ -36,14 +36,26 @@ export const jsdocLinkify = (s: string, schemaNames: string[]) =>
);

export function contentRef(
o: Schema | OpenAPIV3.RequestBodyObject | undefined
o: Schema | OpenAPIV3.RequestBodyObject | undefined,
prefix = ""
) {
return o &&
"content" in o &&
o.content?.["application/json"]?.schema &&
"$ref" in o.content["application/json"].schema
? o.content["application/json"].schema.$ref
: null;
if (!(o && "content" in o && o.content?.["application/json"]?.schema)) {
return null;
}
const schema = o.content["application/json"].schema;

if ("$ref" in schema) {
return prefix + refToSchemaName(schema.$ref);
}

if (schema.type === "array") {
if ("$ref" in schema.items) {
return prefix + refToSchemaName(schema.items.$ref) + "[]";
}
return null;
}

return null;
}

/**
22 changes: 8 additions & 14 deletions generator/client/msw-handlers.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@

import type { OpenAPIV3 } from "openapi-types";
import { initIO } from "../io";
import { refToSchemaName } from "../schema/base";
import { snakeToCamel, snakeToPascal } from "../util";
import { contentRef, iterPathConfig } from "./base";
import path from "node:path";
@@ -83,13 +82,9 @@ export function generateMSWHandlers(spec: OpenAPIV3.Document, destDir: string) {
conf.responses["202"] ||
conf.responses["204"];

const successTypeRef = contentRef(successResponse);
const successType = successTypeRef
? "Api." + refToSchemaName(successTypeRef)
: "void";
const successType = contentRef(successResponse, "Api.");

const bodyTypeRef = contentRef(conf.requestBody);
const bodyType = bodyTypeRef ? refToSchemaName(bodyTypeRef) : null;
const bodyType = contentRef(conf.requestBody);
const body =
bodyType && (method === "post" || method === "put")
? `body: Json<Api.${bodyType}>,`
@@ -108,10 +103,9 @@ export function generateMSWHandlers(spec: OpenAPIV3.Document, destDir: string) {
: "";
const params = `params: { ${pathParamsType} ${queryParamsType} ${body} req: Request, cookies: Record<string, string> }`;

const resultType =
successType === "void"
? "Promisable<StatusCode>"
: `Promisable<HandlerResult<${successType}>>`;
const resultType = successType
? `Promisable<HandlerResult<${successType}>>`
: "Promisable<StatusCode>";

w(`/** \`${method.toUpperCase()} ${formatPath(path)}\` */`);
w(` ${opName}: (${params}) => ${resultType},`);
@@ -210,10 +204,10 @@ export function generateMSWHandlers(spec: OpenAPIV3.Document, destDir: string) {
return [`);
for (const { path, method, opId, conf } of iterPathConfig(spec.paths)) {
const handler = snakeToCamel(opId);
const bodyTypeRef = contentRef(conf.requestBody);
const bodyType = contentRef(conf.requestBody, "schema.");
const bodySchema =
bodyTypeRef && (method === "post" || method === "put")
? `schema.${refToSchemaName(bodyTypeRef)}`
bodyType !== "void" && (method === "post" || method === "put")
? bodyType
: "null";
const paramSchema = conf.parameters?.length
? `schema.${snakeToPascal(opId)}Params`
Loading