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

feat(cmd-api-server): swagger.json endpoints #1877

Open
petermetz opened this issue Feb 23, 2022 · 1 comment
Open

feat(cmd-api-server): swagger.json endpoints #1877

petermetz opened this issue Feb 23, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request P1 Priority 1: Highest Security Related to existing or potential security vulnerabilities
Milestone

Comments

@petermetz
Copy link
Member

Is your feature request related to a problem? Please describe.

The API server currently does not have the ability to serve up the swagger.json (openapi.json) files via HTTP

Describe the solution you'd like

  • Each plugin should have a dedicated endpoint that returns the OpenAPI spec json file.
  • The API server itself should also do the same for it's own services
  • The web service plugins all need to be updated to contain an endpoint that does the serving of the file
  • The code for this web service should be somehow reused across plugins instead of being copy pasted over to each and every one of them. Probably the cactus-core package is a good place to start, but this might not be the best solution, make sure to check.

Describe alternatives you've considered

This #431
They are not mutually exclusive, but wanted to reference the other task here just for providing more complete information to the reader.

Additional context

We need the serving of the OpenAPI spec files for various reasons, one of them is that our fuzzer could leverage that for targeted scanning in a completely automated way which would be really great for us.

@petermetz petermetz added enhancement New feature or request Security Related to existing or potential security vulnerabilities P1 Priority 1: Highest labels Feb 23, 2022
@petermetz petermetz self-assigned this Mar 14, 2022
@charellesandig
Copy link
Contributor

Hi @petermetz I'll be working on this one, thank you!

charellesandig added a commit to charellesandig/cactus that referenced this issue Apr 26, 2022
fixes: hyperledger#1877
Signed-off-by: charellesandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Apr 26, 2022
fixes: hyperledger#1877
Signed-off-by: charellesandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Apr 27, 2022
fixes: hyperledger#1877
Signed-off-by: charellesandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Apr 27, 2022
fixes: hyperledger#1877
Signed-off-by: charellesandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Apr 27, 2022
fixes: hyperledger#1877
Signed-off-by: charellesandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue May 23, 2022
fixes: hyperledger#1877
Signed-off-by: charellesandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue May 23, 2022
fixes: hyperledger#1877
Signed-off-by: charellesandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue May 23, 2022
fixes: hyperledger#1877
Signed-off-by: charellesandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Jul 26, 2022
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Jul 26, 2022
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Jan 3, 2023
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Feb 13, 2023
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Feb 13, 2023
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Feb 13, 2023
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Feb 13, 2023
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Feb 13, 2023
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Feb 13, 2023
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Feb 13, 2023
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Feb 14, 2023
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Feb 14, 2023
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Apr 19, 2023
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Apr 19, 2023
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Apr 19, 2023
fixes: hyperledger#1877
Signed-off-by: charelle.sandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Apr 20, 2023
fixes: hyperledger#1877
Signed-off-by: charelle <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Apr 20, 2023
fixes: hyperledger#1877
Signed-off-by: charelle.sandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Apr 20, 2023
fixes: hyperledger#1877
Signed-off-by: charelle.sandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue Apr 25, 2023
fixes: hyperledger#1877
Signed-off-by: charelle.sandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue May 2, 2023
fixes: hyperledger#1877
Signed-off-by: charelle.sandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue May 3, 2023
fixes: hyperledger#1877
Signed-off-by: charelle.sandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue May 4, 2023
fixes: hyperledger#1877
Signed-off-by: charelle.sandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue May 4, 2023
fixes: hyperledger#1877
Signed-off-by: charelle.sandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue May 4, 2023
fixes: hyperledger#1877
Signed-off-by: charelle.sandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue May 8, 2023
fixes: hyperledger#1877
Signed-off-by: charelle.sandig <charelle.wrk@gmail.com>
charellesandig added a commit to charellesandig/cactus that referenced this issue May 9, 2023
fixes: hyperledger#1877
Signed-off-by: charelle.sandig <charelle.wrk@gmail.com>
adrianbatuto pushed a commit to adrianbatuto/cacti that referenced this issue May 23, 2023
fixes: hyperledger#1877
Signed-off-by: charelle.sandig <charelle.wrk@gmail.com>
adrianbatuto added a commit to charellesandig/cactus that referenced this issue May 30, 2023
fixes: hyperledger#1877
Signed-off-by: adrianbatuto <adrian.batuto@accenture.com>
@petermetz petermetz added this to the v2.0.0-rc.0 milestone Aug 22, 2023
petermetz added a commit to charellesandig/cactus that referenced this issue Sep 14, 2023
This is the pre-requisite to finishing the task at
hyperledger#1877

Having this generic endpoint class available will allow us to send in
another commit which then uses it to create the Open API spec endpoints
in all the plugin classes.

Example usage of the generic class looks like this:

```typescript
import {
  GetOpenApiSpecV1EndpointBase,
  IGetOpenApiSpecV1EndpointBaseOptions,
} from "@hyperledger/cactus-core";

import { Checks, LogLevelDesc } from "@hyperledger/cactus-common";
import { IWebServiceEndpoint } from "@hyperledger/cactus-core-api";

import OAS from "../../json/openapi.json";

export const OasPathGetOpenApiSpecV1 =
  OAS.paths[
    "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec"
  ];

export type OasPathTypeGetOpenApiSpecV1 = typeof OasPathGetOpenApiSpecV1;

export interface IGetOpenApiSpecV1EndpointOptions
  extends IGetOpenApiSpecV1EndpointBaseOptions<
    typeof OAS,
    OasPathTypeGetOpenApiSpecV1
  > {
  readonly logLevel?: LogLevelDesc;
}

export class GetOpenApiSpecV1Endpoint
  extends GetOpenApiSpecV1EndpointBase<typeof OAS, OasPathTypeGetOpenApiSpecV1>
  implements IWebServiceEndpoint
{
  public get className(): string {
    return GetOpenApiSpecV1Endpoint.CLASS_NAME;
  }

  constructor(public readonly options: IGetOpenApiSpecV1EndpointOptions) {
    super(options);
    const fnTag = `${this.className}#constructor()`;
    Checks.truthy(options, `${fnTag} arg options`);
  }
}
```

And the associated OpenAPI specification's paths entry:

```json
"/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec": {
  "get": {
    "x-hyperledger-cactus": {
      "http": {
        "verbLowerCase": "get",
        "path": "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec"
      }
    },
    "operationId": "getOpenApiSpecV1",
    "summary": "Retrieves the .json file that contains the OpenAPI specification for the plugin.",
    "parameters": [],
    "responses": {
      "200": {
        "description": "OK",
        "content": {
          "application/json": {
            "schema": {
              "type": "string"
            }
          }
        }
      }
    }
  }
},
```

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
petermetz added a commit to charellesandig/cactus that referenced this issue Sep 14, 2023
This is the pre-requisite to finishing the task at
hyperledger#1877

Having this generic endpoint class available will allow us to send in
another commit which then uses it to create the Open API spec endpoints
in all the plugin classes.

Example usage of the generic class looks like this:

```typescript
import {
  GetOpenApiSpecV1EndpointBase,
  IGetOpenApiSpecV1EndpointBaseOptions,
} from "@hyperledger/cactus-core";

import { Checks, LogLevelDesc } from "@hyperledger/cactus-common";
import { IWebServiceEndpoint } from "@hyperledger/cactus-core-api";

import OAS from "../../json/openapi.json";

export const OasPathGetOpenApiSpecV1 =
  OAS.paths[
    "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec"
  ];

export type OasPathTypeGetOpenApiSpecV1 = typeof OasPathGetOpenApiSpecV1;

export interface IGetOpenApiSpecV1EndpointOptions
  extends IGetOpenApiSpecV1EndpointBaseOptions<
    typeof OAS,
    OasPathTypeGetOpenApiSpecV1
  > {
  readonly logLevel?: LogLevelDesc;
}

export class GetOpenApiSpecV1Endpoint
  extends GetOpenApiSpecV1EndpointBase<typeof OAS, OasPathTypeGetOpenApiSpecV1>
  implements IWebServiceEndpoint
{
  public get className(): string {
    return GetOpenApiSpecV1Endpoint.CLASS_NAME;
  }

  constructor(public readonly options: IGetOpenApiSpecV1EndpointOptions) {
    super(options);
    const fnTag = `${this.className}#constructor()`;
    Checks.truthy(options, `${fnTag} arg options`);
  }
}
```

And the associated OpenAPI specification's paths entry:

```json
"/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec": {
  "get": {
    "x-hyperledger-cactus": {
      "http": {
        "verbLowerCase": "get",
        "path": "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec"
      }
    },
    "operationId": "getOpenApiSpecV1",
    "summary": "Retrieves the .json file that contains the OpenAPI specification for the plugin.",
    "parameters": [],
    "responses": {
      "200": {
        "description": "OK",
        "content": {
          "application/json": {
            "schema": {
              "type": "string"
            }
          }
        }
      }
    }
  }
},
```

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
petermetz added a commit to charellesandig/cactus that referenced this issue Sep 14, 2023
This is the pre-requisite to finishing the task at
hyperledger#1877

Having this generic endpoint class available will allow us to send in
another commit which then uses it to create the Open API spec endpoints
in all the plugin classes.

Example usage of the generic class looks like this:

```typescript
import {
  GetOpenApiSpecV1EndpointBase,
  IGetOpenApiSpecV1EndpointBaseOptions,
} from "@hyperledger/cactus-core";

import { Checks, LogLevelDesc } from "@hyperledger/cactus-common";
import { IWebServiceEndpoint } from "@hyperledger/cactus-core-api";

import OAS from "../../json/openapi.json";

export const OasPathGetOpenApiSpecV1 =
  OAS.paths[
    "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec"
  ];

export type OasPathTypeGetOpenApiSpecV1 = typeof OasPathGetOpenApiSpecV1;

export interface IGetOpenApiSpecV1EndpointOptions
  extends IGetOpenApiSpecV1EndpointBaseOptions<
    typeof OAS,
    OasPathTypeGetOpenApiSpecV1
  > {
  readonly logLevel?: LogLevelDesc;
}

export class GetOpenApiSpecV1Endpoint
  extends GetOpenApiSpecV1EndpointBase<typeof OAS, OasPathTypeGetOpenApiSpecV1>
  implements IWebServiceEndpoint
{
  public get className(): string {
    return GetOpenApiSpecV1Endpoint.CLASS_NAME;
  }

  constructor(public readonly options: IGetOpenApiSpecV1EndpointOptions) {
    super(options);
    const fnTag = `${this.className}#constructor()`;
    Checks.truthy(options, `${fnTag} arg options`);
  }
}
```

And the associated OpenAPI specification's paths entry:

```json
"/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec": {
  "get": {
    "x-hyperledger-cactus": {
      "http": {
        "verbLowerCase": "get",
        "path": "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec"
      }
    },
    "operationId": "getOpenApiSpecV1",
    "summary": "Retrieves the .json file that contains the OpenAPI specification for the plugin.",
    "parameters": [],
    "responses": {
      "200": {
        "description": "OK",
        "content": {
          "application/json": {
            "schema": {
              "type": "string"
            }
          }
        }
      }
    }
  }
},
```

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
petermetz added a commit to charellesandig/cactus that referenced this issue Sep 15, 2023
This is the pre-requisite to finishing the task at
hyperledger#1877

Having this generic endpoint class available will allow us to send in
another commit which then uses it to create the Open API spec endpoints
in all the plugin classes.

Example usage of the generic class looks like this:

```typescript
import {
  GetOpenApiSpecV1EndpointBase,
  IGetOpenApiSpecV1EndpointBaseOptions,
} from "@hyperledger/cactus-core";

import { Checks, LogLevelDesc } from "@hyperledger/cactus-common";
import { IWebServiceEndpoint } from "@hyperledger/cactus-core-api";

import OAS from "../../json/openapi.json";

export const OasPathGetOpenApiSpecV1 =
  OAS.paths[
    "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec"
  ];

export type OasPathTypeGetOpenApiSpecV1 = typeof OasPathGetOpenApiSpecV1;

export interface IGetOpenApiSpecV1EndpointOptions
  extends IGetOpenApiSpecV1EndpointBaseOptions<
    typeof OAS,
    OasPathTypeGetOpenApiSpecV1
  > {
  readonly logLevel?: LogLevelDesc;
}

export class GetOpenApiSpecV1Endpoint
  extends GetOpenApiSpecV1EndpointBase<typeof OAS, OasPathTypeGetOpenApiSpecV1>
  implements IWebServiceEndpoint
{
  public get className(): string {
    return GetOpenApiSpecV1Endpoint.CLASS_NAME;
  }

  constructor(public readonly options: IGetOpenApiSpecV1EndpointOptions) {
    super(options);
    const fnTag = `${this.className}#constructor()`;
    Checks.truthy(options, `${fnTag} arg options`);
  }
}
```

And the associated OpenAPI specification's paths entry:

```json
"/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec": {
  "get": {
    "x-hyperledger-cactus": {
      "http": {
        "verbLowerCase": "get",
        "path": "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec"
      }
    },
    "operationId": "getOpenApiSpecV1",
    "summary": "Retrieves the .json file that contains the OpenAPI specification for the plugin.",
    "parameters": [],
    "responses": {
      "200": {
        "description": "OK",
        "content": {
          "application/json": {
            "schema": {
              "type": "string"
            }
          }
        }
      }
    }
  }
},
```

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
petermetz added a commit that referenced this issue Sep 17, 2023
This is the pre-requisite to finishing the task at
#1877

Having this generic endpoint class available will allow us to send in
another commit which then uses it to create the Open API spec endpoints
in all the plugin classes.

Example usage of the generic class looks like this:

```typescript
import {
  GetOpenApiSpecV1EndpointBase,
  IGetOpenApiSpecV1EndpointBaseOptions,
} from "@hyperledger/cactus-core";

import { Checks, LogLevelDesc } from "@hyperledger/cactus-common";
import { IWebServiceEndpoint } from "@hyperledger/cactus-core-api";

import OAS from "../../json/openapi.json";

export const OasPathGetOpenApiSpecV1 =
  OAS.paths[
    "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec"
  ];

export type OasPathTypeGetOpenApiSpecV1 = typeof OasPathGetOpenApiSpecV1;

export interface IGetOpenApiSpecV1EndpointOptions
  extends IGetOpenApiSpecV1EndpointBaseOptions<
    typeof OAS,
    OasPathTypeGetOpenApiSpecV1
  > {
  readonly logLevel?: LogLevelDesc;
}

export class GetOpenApiSpecV1Endpoint
  extends GetOpenApiSpecV1EndpointBase<typeof OAS, OasPathTypeGetOpenApiSpecV1>
  implements IWebServiceEndpoint
{
  public get className(): string {
    return GetOpenApiSpecV1Endpoint.CLASS_NAME;
  }

  constructor(public readonly options: IGetOpenApiSpecV1EndpointOptions) {
    super(options);
    const fnTag = `${this.className}#constructor()`;
    Checks.truthy(options, `${fnTag} arg options`);
  }
}
```

And the associated OpenAPI specification's paths entry:

```json
"/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec": {
  "get": {
    "x-hyperledger-cactus": {
      "http": {
        "verbLowerCase": "get",
        "path": "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec"
      }
    },
    "operationId": "getOpenApiSpecV1",
    "summary": "Retrieves the .json file that contains the OpenAPI specification for the plugin.",
    "parameters": [],
    "responses": {
      "200": {
        "description": "OK",
        "content": {
          "application/json": {
            "schema": {
              "type": "string"
            }
          }
        }
      }
    }
  }
},
```

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
sandeepnRES pushed a commit to sandeepnRES/cacti that referenced this issue Dec 21, 2023
This is the pre-requisite to finishing the task at
hyperledger#1877

Having this generic endpoint class available will allow us to send in
another commit which then uses it to create the Open API spec endpoints
in all the plugin classes.

Example usage of the generic class looks like this:

```typescript
import {
  GetOpenApiSpecV1EndpointBase,
  IGetOpenApiSpecV1EndpointBaseOptions,
} from "@hyperledger/cactus-core";

import { Checks, LogLevelDesc } from "@hyperledger/cactus-common";
import { IWebServiceEndpoint } from "@hyperledger/cactus-core-api";

import OAS from "../../json/openapi.json";

export const OasPathGetOpenApiSpecV1 =
  OAS.paths[
    "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec"
  ];

export type OasPathTypeGetOpenApiSpecV1 = typeof OasPathGetOpenApiSpecV1;

export interface IGetOpenApiSpecV1EndpointOptions
  extends IGetOpenApiSpecV1EndpointBaseOptions<
    typeof OAS,
    OasPathTypeGetOpenApiSpecV1
  > {
  readonly logLevel?: LogLevelDesc;
}

export class GetOpenApiSpecV1Endpoint
  extends GetOpenApiSpecV1EndpointBase<typeof OAS, OasPathTypeGetOpenApiSpecV1>
  implements IWebServiceEndpoint
{
  public get className(): string {
    return GetOpenApiSpecV1Endpoint.CLASS_NAME;
  }

  constructor(public readonly options: IGetOpenApiSpecV1EndpointOptions) {
    super(options);
    const fnTag = `${this.className}#constructor()`;
    Checks.truthy(options, `${fnTag} arg options`);
  }
}
```

And the associated OpenAPI specification's paths entry:

```json
"/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec": {
  "get": {
    "x-hyperledger-cactus": {
      "http": {
        "verbLowerCase": "get",
        "path": "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-open-api-spec"
      }
    },
    "operationId": "getOpenApiSpecV1",
    "summary": "Retrieves the .json file that contains the OpenAPI specification for the plugin.",
    "parameters": [],
    "responses": {
      "200": {
        "description": "OK",
        "content": {
          "application/json": {
            "schema": {
              "type": "string"
            }
          }
        }
      }
    }
  }
},
```

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1 Priority 1: Highest Security Related to existing or potential security vulnerabilities
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

2 participants