Skip to content

Commit

Permalink
Linguist api docs (#2062)
Browse files Browse the repository at this point in the history
* Add openapi spec for linguist

Signed-off-by: Brian Forbis <[email protected]>

* Add changeset

Signed-off-by: Brian Forbis <[email protected]>

* Update workspaces/linguist/plugins/linguist-backend/README.md

Co-authored-by: Andre Wanlin <[email protected]>
Signed-off-by: bforbis <[email protected]>

---------

Signed-off-by: Brian Forbis <[email protected]>
Signed-off-by: bforbis <[email protected]>
Co-authored-by: Andre Wanlin <[email protected]>
  • Loading branch information
bforbis and awanlin authored Jan 7, 2025
1 parent dfa0a7d commit 8585c65
Show file tree
Hide file tree
Showing 11 changed files with 353 additions and 11 deletions.
5 changes: 5 additions & 0 deletions workspaces/linguist/.changeset/fast-seahorses-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage-community/plugin-linguist-backend': minor
---

Added openapi spec for linguist backend
7 changes: 6 additions & 1 deletion workspaces/linguist/app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ catalog:
target: ../../examples/org.yaml
rules:
- allow: [User, Group]

providers:
backstageOpenapi:
plugins:
- catalog
- search
- linguist
linguist:
linguistJsOptions:
categories: ['programming']
Expand Down
1 change: 1 addition & 0 deletions workspaces/linguist/packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@backstage/plugin-auth-backend-module-guest-provider": "^0.2.3",
"@backstage/plugin-auth-node": "^0.5.5",
"@backstage/plugin-catalog-backend": "^1.29.0",
"@backstage/plugin-catalog-backend-module-backstage-openapi": "^0.4.2",
"@backstage/plugin-catalog-backend-module-scaffolder-entity-model": "^0.2.3",
"@backstage/plugin-permission-backend": "^0.5.52",
"@backstage/plugin-permission-backend-module-allow-all-policy": "^0.2.3",
Expand Down
5 changes: 5 additions & 0 deletions workspaces/linguist/packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ backend.add(
),
);

// openapi plugin
backend.add(
import('@backstage/plugin-catalog-backend-module-backstage-openapi'),
);

// permission plugin
backend.add(import('@backstage/plugin-permission-backend/alpha'));
backend.add(
Expand Down
4 changes: 4 additions & 0 deletions workspaces/linguist/plugins/linguist-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Here's how to get the backend up and running:
4. Now run `yarn start-backend` from the repo root
5. Finally open `http://localhost:7007/api/linguist/health` in a browser and it should return `{"status":"ok"}`

## Linguist Backend API

The linguist backend provides API documentation through OpenAPI. To view the OpenAPI spec for your backstage instance, consider installing [`@backstage/plugin-catalog-backend-module-backstage-openapi`](https://github.com/backstage/backstage/blob/master/plugins/catalog-backend-module-backstage-openapi/README.md).

## Plugin Options

The Linguist backend has various plugin options that you can provide in the `app-config.yaml` file that will allow you to configure various aspects of how it works. The following sections go into the details of these options
Expand Down
3 changes: 3 additions & 0 deletions workspaces/linguist/plugins/linguist-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"scripts": {
"build": "backstage-cli package build",
"clean": "backstage-cli package clean",
"generate": "backstage-repo-tools package schema openapi generate --server",
"lint": "backstage-cli package lint",
"prepack": "backstage-cli package prepack",
"postpack": "backstage-cli package postpack",
Expand All @@ -41,6 +42,7 @@
"dependencies": {
"@backstage-community/plugin-linguist-common": "workspace:^",
"@backstage/backend-defaults": "^0.6.1",
"@backstage/backend-openapi-utils": "^0.4.0",
"@backstage/backend-plugin-api": "^1.1.0",
"@backstage/catalog-client": "^1.9.0",
"@backstage/catalog-model": "^1.7.2",
Expand All @@ -62,6 +64,7 @@
"devDependencies": {
"@backstage/backend-test-utils": "^1.2.0",
"@backstage/cli": "^0.29.4",
"@backstage/repo-tools": "^0.12.0",
"@types/fs-extra": "^11.0.0",
"@types/node-fetch": "^2.5.12",
"@types/supertest": "^6.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/*
* Copyright 2024 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// ******************************************************************
// * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. *
// ******************************************************************
import { createValidatedOpenApiRouter } from '@backstage/backend-openapi-utils';

export const spec = {
openapi: '3.0.3',
info: {
title: 'linguist',
description:
'This API powers the backend for the linguist plugins of backstage.',
version: '1.0',
license: {
name: 'Apache-2.0',
url: 'http://www.apache.org/licenses/LICENSE-2.0.html',
},
contact: {},
},
servers: [
{
url: '/',
},
],
paths: {
'/health': {
get: {
description: 'Checks if the linguist backend is hooked up properly',
responses: {
'200': {
description: 'OK',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
status: {
type: 'string',
},
},
},
},
},
},
},
},
},
'/entity-languages': {
get: {
description:
'Returns the language breakdown of the passed in entityRef.',
parameters: [
{
in: 'query',
description:
'Reference passed in the format <kind>:<namespace>/<name>',
example: 'component:default/my-component',
name: 'entityRef',
required: true,
schema: {
type: 'string',
},
},
],
responses: {
'200': {
description: 'OK',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Languages',
},
},
},
},
'500': {
$ref: '#/components/responses/ServerError',
},
},
},
},
},
components: {
examples: {},
headers: {},
parameters: {},
requestBodies: {},
responses: {
ServerError: {
description: 'Error',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
error: {
type: 'object',
properties: {
name: {
type: 'string',
example: 'Error',
},
message: {
type: 'string',
example: 'No entityRef was provided',
},
},
},
},
},
},
},
},
},
schemas: {
LanguageType: {
type: 'string',
enum: ['programming', 'data', 'markup', 'prose'],
example: 'programming',
},
Language: {
type: 'object',
properties: {
name: {
type: 'string',
example: 'java',
},
percentage: {
type: 'number',
example: 20.03,
},
bytes: {
type: 'number',
example: 3000,
},
type: {
$ref: '#/components/schemas/LanguageType',
},
color: {
type: 'string',
example: '#f1e05a',
},
},
},
Languages: {
type: 'object',
properties: {
languageCount: {
type: 'number',
example: 3,
},
totalBytes: {
type: 'number',
example: 10000,
},
processedDate: {
type: 'string',
example: '2024-11-15T18:17:29.460Z',
},
breakdown: {
type: 'array',
items: {
$ref: '#/components/schemas/Language',
},
},
},
},
},
},
} as const;
export const createOpenApiRouter = async (
options?: Parameters<typeof createValidatedOpenApiRouter>['1'],
) => createValidatedOpenApiRouter<typeof spec>(spec, options);
109 changes: 109 additions & 0 deletions workspaces/linguist/plugins/linguist-backend/src/schema/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
openapi: '3.0.3'
info:
title: linguist
description: This API powers the backend for the linguist plugins of backstage.
version: '1.0'
license:
name: Apache-2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
contact: {}
servers:
- url: /
paths:
/health:
get:
description: Checks if the linguist backend is hooked up properly
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
status:
type: string
/entity-languages:
get:
description: Returns the language breakdown of the passed in entityRef.
parameters:
- in: query
description: Reference passed in the format <kind>:<namespace>/<name>
example: component:default/my-component
name: entityRef
required: true
schema:
type: string
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Languages'
'500':
$ref: '#/components/responses/ServerError'
components:
examples: {}
headers: {}
parameters: {}
requestBodies: {}
responses:
ServerError:
description: Error
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
name:
type: string
example: Error
message:
type: string
example: No entityRef was provided
schemas:
LanguageType:
type: string
enum:
- programming
- data
- markup
- prose
example: programming
Language:
type: object
properties:
name:
type: string
example: java
percentage:
type: number
example: 20.03
bytes:
type: number
example: 3000
type:
$ref: '#/components/schemas/LanguageType'
color:
type: string
example: '#f1e05a'
Languages:
type: object
properties:
languageCount:
type: number
example: 3
totalBytes:
type: number
example: 10000
processedDate:
type: string
example: 2024-11-15T18:17:29.460Z
breakdown:
type: array
items:
$ref: '#/components/schemas/Language'
Loading

0 comments on commit 8585c65

Please sign in to comment.