diff --git a/packages/daf-cli/default/default.yml b/packages/daf-cli/default/default.yml index 77277b757..15fca0aa4 100644 --- a/packages/daf-cli/default/default.yml +++ b/packages/daf-cli/default/default.yml @@ -9,6 +9,8 @@ server: # $env: API_KEY schemaPath: /open-api.json # homePageTemplate: ./homepage.html + apiName: Agent + apiVersion: 1.0.0 apiBasePath: /agent apiDocsPath: /api-docs defaultIdentity: diff --git a/packages/daf-cli/src/server.ts b/packages/daf-cli/src/server.ts index 6fe8c5ce3..56305d1f3 100644 --- a/packages/daf-cli/src/server.ts +++ b/packages/daf-cli/src/server.ts @@ -45,10 +45,6 @@ program console.error(e) process.exit() } - process.on('SIGINT', function(code) { - console.log('Killing ngrok') - ngrok.kill() - }); app.set('trust proxy', 'loopback') } const hostname = parse(baseUrl).hostname @@ -103,6 +99,8 @@ program getAgentForRequest, exposedMethods, securityScheme, + apiName: options.apiName, + apiVersion: options.apiVersion, }), ) diff --git a/packages/daf-express/api/daf-express.api.md b/packages/daf-express/api/daf-express.api.md index 59cd42c41..53cf2a293 100644 --- a/packages/daf-express/api/daf-express.api.md +++ b/packages/daf-express/api/daf-express.api.md @@ -24,6 +24,8 @@ export const ApiSchemaRouter: (options: ApiSchemaRouterOptions) => Router; // @public (undocumented) export interface ApiSchemaRouterOptions { + apiName?: string; + apiVersion?: string; basePath: string; exposedMethods: Array; getAgentForRequest: (req: Request_2) => Promise; diff --git a/packages/daf-express/src/api-schema-router.ts b/packages/daf-express/src/api-schema-router.ts index 48dc1d402..6684a80c4 100644 --- a/packages/daf-express/src/api-schema-router.ts +++ b/packages/daf-express/src/api-schema-router.ts @@ -33,6 +33,16 @@ export interface ApiSchemaRouterOptions { * ``` */ securityScheme?: string + + /** + * Name used in OpenAPI schema + */ + apiName?: string + + /** + * Version used in OpenAPI schema + */ + apiVersion?: string } /** @@ -50,7 +60,7 @@ export const ApiSchemaRouter = (options: ApiSchemaRouterOptions): Router => { router.get('/', (req: RequestWithAgent, res) => { if (req.agent) { - const openApiSchema = getOpenApiSchema(req.agent, '', options.exposedMethods) + const openApiSchema = getOpenApiSchema(req.agent, '', options.exposedMethods, options.apiName, options.apiVersion) const url = (req.headers['x-forwarded-proto'] || req.protocol) + '://' + req.hostname + options.basePath openApiSchema.servers = [{ url }] diff --git a/packages/daf-rest/api/daf-rest.api.md b/packages/daf-rest/api/daf-rest.api.md index b9902f118..ddee02a00 100644 --- a/packages/daf-rest/api/daf-rest.api.md +++ b/packages/daf-rest/api/daf-rest.api.md @@ -25,7 +25,7 @@ export class AgentRestClient implements IAgentPlugin { } // @public (undocumented) -export const getOpenApiSchema: (agent: IAgent, basePath: string, exposedMethods: Array) => OpenAPIV3.Document; +export const getOpenApiSchema: (agent: IAgent, basePath: string, exposedMethods: Array, name?: string | undefined, version?: string | undefined) => OpenAPIV3.Document; ``` diff --git a/packages/daf-rest/src/openApi.ts b/packages/daf-rest/src/openApi.ts index 56c230004..6747debd0 100644 --- a/packages/daf-rest/src/openApi.ts +++ b/packages/daf-rest/src/openApi.ts @@ -1,7 +1,7 @@ import { OpenAPIV3 } from 'openapi-types' import { IAgent } from 'daf-core' -export const getOpenApiSchema = (agent: IAgent, basePath: string, exposedMethods: Array): OpenAPIV3.Document => { +export const getOpenApiSchema = (agent: IAgent, basePath: string, exposedMethods: Array, name?: string, version?: string): OpenAPIV3.Document => { const agentSchema = agent.getSchema() const paths: OpenAPIV3.PathsObject = {} @@ -47,14 +47,19 @@ export const getOpenApiSchema = (agent: IAgent, basePath: string, exposedMethods const openApi: OpenAPIV3.Document = { openapi: "3.0.0", info: { - title: "DID Agent", - version: "" + title: name || "DID Agent", + version: version || "" }, components:{ - schemas: agent.getSchema().components.schemas + schemas: agent.getSchema().components.schemas, }, paths } + if (openApi.components?.schemas) { + //@ts-ignore + openApi['x-methods'] = agent.getSchema().components.methods + } + return openApi }