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

[nexus] OpenAPI schema not marking required query params required #7155

Open
david-crespo opened this issue Nov 23, 2024 · 0 comments
Open

Comments

@david-crespo
Copy link
Contributor

david-crespo commented Nov 23, 2024

The selector struct (correct)

InternetGatewaySelector selects a gateway. It correctly has a required gateway field and optional project and vpc, representing the possibility of selecting by gateway ID, in which case neither of the parent identifiers can be included.

pub struct InternetGatewaySelector {
/// Name or ID of the project, only required if `vpc` is provided as a `Name`
pub project: Option<NameOrId>,
/// Name or ID of the VPC, only required if `gateway` is provided as a `Name`
pub vpc: Option<NameOrId>,
/// Name or ID of the internet gateway
pub gateway: NameOrId,
}

The endpoints

These two endpoints use InternetGatewaySelector as their query params to select a gateway. The fact that

/// List IP pools attached to internet gateway
#[endpoint {
method = GET,
path = "/v1/internet-gateway-ip-pools",
tags = ["vpcs"],
}]
async fn internet_gateway_ip_pool_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<
PaginatedByNameOrId<params::InternetGatewaySelector>,
>,
) -> Result<
HttpResponseOk<ResultsPage<views::InternetGatewayIpPool>>,
HttpError,
>;

/// List IP addresses attached to internet gateway
#[endpoint {
method = GET,
path = "/v1/internet-gateway-ip-addresses",
tags = ["vpcs"],
}]
async fn internet_gateway_ip_address_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<
PaginatedByNameOrId<params::InternetGatewaySelector>,
>,
) -> Result<
HttpResponseOk<ResultsPage<views::InternetGatewayIpAddress>>,
HttpError,
>;

The OpenAPI schema (wrong)

The gateway query param is optional, but it should not be.

omicron/openapi/nexus.json

Lines 2685 to 2694 in adaa2ec

"operationId": "internet_gateway_ip_address_list",
"parameters": [
{
"in": "query",
"name": "gateway",
"description": "Name or ID of the internet gateway",
"schema": {
"$ref": "#/components/schemas/NameOrId"
}
},

omicron/openapi/nexus.json

Lines 2895 to 2904 in adaa2ec

"operationId": "internet_gateway_ip_pool_list",
"parameters": [
{
"in": "query",
"name": "gateway",
"description": "Name or ID of the internet gateway",
"schema": {
"$ref": "#/components/schemas/NameOrId"
}
},

The TypeScript type generated accordingly

https://github.com/oxidecomputer/console/blob/653b572/app/api/__generated__/Api.ts#L4541-L4548

export interface InternetGatewayIpPoolListQueryParams {
  gateway?: NameOrId
  limit?: number
  pageToken?: string
  project?: NameOrId
  sortBy?: NameOrIdSortMode
  vpc?: NameOrId
}

What a required query param looks like

omicron/openapi/nexus.json

Lines 1824 to 1840 in adaa2ec

"post": {
"tags": [
"instances"
],
"summary": "Create instance",
"operationId": "instance_create",
"parameters": [
{
"in": "query",
"name": "project",
"description": "Name or ID of the project",
"required": true,
"schema": {
"$ref": "#/components/schemas/NameOrId"
}
}
],

An unrelated endpoint with the same issue

This suggests it might have something to do with nesting it in the pagination thing.

/// List network interfaces
#[endpoint {
method = GET,
path = "/v1/network-interfaces",
tags = ["instances"],
}]
async fn instance_network_interface_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<PaginatedByNameOrId<params::InstanceSelector>>,
) -> Result<HttpResponseOk<ResultsPage<InstanceNetworkInterface>>, HttpError>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant