Skip to content

Commit

Permalink
[Security Solution] Enable OpenAPI schemas linting in Security Soluti…
Browse files Browse the repository at this point in the history
…on plugin (#188529)

**Relates to:** elastic/security-team#9401

## Summary

Disabling OpenAPI spec linting in #179074 lead to accumulating invalid OpenAPi specs.

This PR enables OpenAPI linting for Security Solution plugin and make appropriate fixes to make the linting pass.

## Details

OpenAPI linting is a part of code generation. It runs automatically but can be disabled via  `skipLinting: true`. Code generation with disabled linting isn't able to catch all possible problems in processing specs.

The majority of problems came from Entity Analytics and Osquery OpenAPI specs. These specs were fixed and refactored to enable code generation and integrate generated artefacts into routes to make sure OpenAPI spec match API endpoints they describe. It helped to catch some subtle inconsistencies.
  • Loading branch information
maximpn authored Jul 22, 2024
1 parent 1ac9c8e commit 7aae5d9
Show file tree
Hide file tree
Showing 88 changed files with 1,077 additions and 718 deletions.
15 changes: 8 additions & 7 deletions packages/kbn-openapi-generator/redocly_linter/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ plugins:

rules:
spec: error
spec-strict-refs: warn
spec-strict-refs: error
no-path-trailing-slash: error
no-identical-paths: error
no-ambiguous-paths: warn
no-ambiguous-paths: error
no-unresolved-refs: error
no-enum-type-mismatch: error
component-name-unique: error
path-declaration-must-exist: error
path-not-include-query: error
path-parameters-defined: warn
operation-description: warn
operation-2xx-response: error
operation-4xx-response: warn
operation-operationId: error
operation-operationId-unique: error
operation-summary: warn
operation-operationId-url-safe: error
operation-parameters-unique: error
boolean-parameter-prefixes: warn
extra-linter-rules-plugin/valid-x-modify: error
# Disable rules generating the majority of warnings.
# They will be handled separately.
# operation-description: warn
# operation-summary: warn
# operation-4xx-response: warn
# path-parameters-defined: warn
37 changes: 37 additions & 0 deletions x-pack/plugins/osquery/common/api/asset/assets.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

/*
* NOTICE: Do not edit this file manually.
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
*
* info:
* title: Assets Schema
* version: 1
*/

import { z } from 'zod';

import { AssetsRequestQuery } from './assets_status.gen';

export type ReadAssetsStatusRequestParams = z.infer<typeof ReadAssetsStatusRequestParams>;
export const ReadAssetsStatusRequestParams = z.object({
query: AssetsRequestQuery,
});
export type ReadAssetsStatusRequestParamsInput = z.input<typeof ReadAssetsStatusRequestParams>;

export type ReadAssetsStatusResponse = z.infer<typeof ReadAssetsStatusResponse>;
export const ReadAssetsStatusResponse = z.object({});

export type UpdateAssetsStatusRequestParams = z.infer<typeof UpdateAssetsStatusRequestParams>;
export const UpdateAssetsStatusRequestParams = z.object({
query: AssetsRequestQuery,
});
export type UpdateAssetsStatusRequestParamsInput = z.input<typeof UpdateAssetsStatusRequestParams>;

export type UpdateAssetsStatusResponse = z.infer<typeof UpdateAssetsStatusResponse>;
export const UpdateAssetsStatusResponse = z.object({});
24 changes: 20 additions & 4 deletions x-pack/plugins/osquery/common/api/asset/assets.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,41 @@ info:
paths:
/internal/osquery/assets:
get:
x-codegen-enabled: true
operationId: ReadAssetsStatus
summary: Get assets
parameters:
- $ref: './assets_status.schema.yaml#/components/parameters/AssetsStatusRequestQueryParameter'
- name: query
in: path
required: true
schema:
$ref: './assets_status.schema.yaml#/components/schemas/AssetsRequestQuery'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: './assets_status.schema.yaml#/components/schemas/SuccessResponse'
type: object
properties: {}
# Define properties for the success response if needed
/internal/osquery/assets/update:
post:
x-codegen-enabled: true
operationId: UpdateAssetsStatus
summary: Update assets
parameters:
- $ref: './assets_status.schema.yaml#/components/parameters/AssetsStatusRequestQueryParameter'
- name: query
in: path
required: true
schema:
$ref: './assets_status.schema.yaml#/components/schemas/AssetsRequestQuery'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: './assets_status.schema.yaml#/components/schemas/SuccessResponse'
type: object
properties: {}
# Define properties for the success response if needed
3 changes: 0 additions & 3 deletions x-pack/plugins/osquery/common/api/asset/assets_status.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,3 @@ import { z } from 'zod';

export type AssetsRequestQuery = z.infer<typeof AssetsRequestQuery>;
export const AssetsRequestQuery = z.object({});

export type SuccessResponse = z.infer<typeof SuccessResponse>;
export const SuccessResponse = z.object({});
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,8 @@ openapi: 3.0.0
info:
title: Assets Status Schema
version: '1'
paths: { }
paths: {}
components:
parameters:
AssetsStatusRequestQueryParameter:
name: query
in: path
required: true
schema:
$ref: '#/components/schemas/AssetsRequestQuery'
schemas:
AssetsRequestQuery:
type: object
SuccessResponse:
type: object
properties: {}
# Define properties for the success response if needed
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

/*
* NOTICE: Do not edit this file manually.
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
*
* info:
* title: Fleet wrapper schema
* version: 1
*/

import { z } from 'zod';

import { Id } from '../model/schema/common_attributes.gen';

export type GetAgentDetailsRequestParams = z.infer<typeof GetAgentDetailsRequestParams>;
export const GetAgentDetailsRequestParams = z.object({
id: Id,
});
export type GetAgentDetailsRequestParamsInput = z.input<typeof GetAgentDetailsRequestParams>;

export type GetAgentDetailsResponse = z.infer<typeof GetAgentDetailsResponse>;
export const GetAgentDetailsResponse = z.object({});

export type GetAgentPackagePoliciesResponse = z.infer<typeof GetAgentPackagePoliciesResponse>;
export const GetAgentPackagePoliciesResponse = z.object({});

export type GetAgentPoliciesResponse = z.infer<typeof GetAgentPoliciesResponse>;
export const GetAgentPoliciesResponse = z.object({});

export type GetAgentPolicyRequestParams = z.infer<typeof GetAgentPolicyRequestParams>;
export const GetAgentPolicyRequestParams = z.object({
id: Id,
});
export type GetAgentPolicyRequestParamsInput = z.input<typeof GetAgentPolicyRequestParams>;

export type GetAgentPolicyResponse = z.infer<typeof GetAgentPolicyResponse>;
export const GetAgentPolicyResponse = z.object({});
export type GetAgentsRequestQuery = z.infer<typeof GetAgentsRequestQuery>;
export const GetAgentsRequestQuery = z.object({
query: z.object({}),
});
export type GetAgentsRequestQueryInput = z.input<typeof GetAgentsRequestQuery>;

export type GetAgentsResponse = z.infer<typeof GetAgentsResponse>;
export const GetAgentsResponse = z.object({});
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,94 @@ info:
paths:
/internal/osquery/fleet_wrapper/agents:
get:
x-codegen-enabled: true
operationId: GetAgents
summary: Get agents
parameters:
- $ref: './get_agents.schema.yaml#/components/parameters/GetAgentsRequestQueryParameter'
- name: query
in: query
required: true
schema:
type: object
additionalProperties: true
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: './get_agents.schema.yaml#/components/schemas/SuccessResponse'
type: object
properties: {}
# Define properties for the success response if needed

/internal/osquery/fleet_wrapper/agents/{id}:
get:
x-codegen-enabled: true
operationId: GetAgentDetails
summary: Get Agent details
parameters:
- $ref: './get_agent_details.schema.yaml#/components/parameters/GetAgentDetailsRequestQueryParameter'
- name: id
in: path
required: true
schema:
$ref: '../model/schema/common_attributes.schema.yaml#/components/schemas/Id'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: './get_agent_details.schema.yaml#/components/schemas/SuccessResponse'
type: object
properties: {}
# Define properties for the success response if needed

/internal/osquery/fleet_wrapper/agent_policies:
get:
x-codegen-enabled: true
operationId: GetAgentPolicies
summary: Get Agent policies
parameters:
- $ref: './get_agent_policies.schema.yaml#/components/parameters/GetAgentPoliciesRequestParameter'
- $ref: './get_agent_policies.schema.yaml#/components/parameters/GetAgentPoliciesRequestQueryParameter'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: './get_agent_policies.schema.yaml#/components/schemas/SuccessResponse'
type: object
properties: {}
# Define properties for the success response if needed

/internal/osquery/fleet_wrapper/agent_policies/{id}:
get:
x-codegen-enabled: true
operationId: GetAgentPolicy
summary: Get Agent policy
parameters:
- $ref: './get_agent_policy.schema.yaml#/components/parameters/GetAgentPolicyRequestParameter'
- name: id
in: path
required: true
schema:
$ref: '../model/schema/common_attributes.schema.yaml#/components/schemas/Id'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: './get_agent_policy.schema.yaml#/components/schemas/SuccessResponse'
type: object
properties: {}
# Define properties for the success response if needed

/internal/osquery/fleet_wrapper/package_policies:
get:
x-codegen-enabled: true
operationId: GetAgentPackagePolicies
summary: Get Agent policy
parameters:
- $ref: './get_package_policies.schema.yaml#/components/parameters/GetPackagePoliciesRequestQueryParameter'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: './get_package_policies.schema.yaml#/components/schemas/SuccessResponse'
type: object
properties: {}
# Define properties for the success response if needed

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7aae5d9

Please sign in to comment.