Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
chore: rewrite generator to resolve strange name generation (#612)
Browse files Browse the repository at this point in the history
* rewrite generator to resolve strange name generation

* fix asset id types

* ignore errored types

* remove depreciated calls

* use more random words

* random user

Former-commit-id: 4738a9b
  • Loading branch information
hay-kot authored Nov 16, 2023
1 parent f74736b commit 742ece7
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 1,183 deletions.
41 changes: 28 additions & 13 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,43 @@ tasks:
- cd backend && go mod tidy
- cd frontend && pnpm install --shamefully-hoist

generate:
desc: |
Generates collateral files from the backend project
including swagger docs and typescripts type for the frontend
deps:
- db:generate
swag:
desc: Generate swagger docs
dir: backend/app/api/static/
vars:
API: "../"
INTERNAL: "../../../internal"
PKGS: "../../../pkgs"
cmds:
- swag fmt --dir={{ .API }}
- swag init --dir={{ .API }},{{ .INTERNAL }}/core/services,{{ .INTERNAL }}/data/repo --parseDependency
sources:
- "./backend/app/api/**/*"
- "./backend/internal/data/**"
- "./backend/internal/core/services/**/*"
- "./backend/app/tools/typegen/main.go"

typescript-types:
desc: Generates typescript types from swagger definition
cmds:
- cd backend/app/api/static && swag fmt --dir=../
- cd backend/app/api/static && swag init --dir=../,../../../internal,../../../pkgs
- |
npx swagger-typescript-api \
--no-client \
--modular \
--path ./backend/app/api/static/docs/swagger.json \
--output ./frontend/lib/api/types
- go run ./backend/app/tools/typegen/main.go ./frontend/lib/api/types/data-contracts.ts
- cp ./backend/app/api/static/docs/swagger.json docs/docs/api/openapi-2.0.json
sources:
- "./backend/app/api/**/*"
- "./backend/internal/data/**"
- "./backend/internal/core/services/**/*"
- "./backend/app/tools/typegen/main.go"
- ./backend/app/tools/typegen/main.go
- ./backend/app/api/static/docs/swagger.json

generate:
deps:
- db:generate
cmds:
- task: swag
- task: typescript-types
- cp ./backend/app/api/static/docs/swagger.json docs/docs/api/openapi-2.0.json

go:run:
desc: Starts the backend api server (depends on generate task)
Expand Down
39 changes: 23 additions & 16 deletions backend/app/api/static/docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Package docs GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"
Expand Down Expand Up @@ -2038,9 +2037,13 @@ const docTemplate = `{
},
"location": {
"description": "Edges",
"allOf": [
{
"$ref": "#/definitions/repo.LocationSummary"
}
],
"x-nullable": true,
"x-omitempty": true,
"$ref": "#/definitions/repo.LocationSummary"
"x-omitempty": true
},
"manufacturer": {
"type": "string"
Expand All @@ -2056,9 +2059,13 @@ const docTemplate = `{
"type": "string"
},
"parent": {
"allOf": [
{
"$ref": "#/definitions/repo.ItemSummary"
}
],
"x-nullable": true,
"x-omitempty": true,
"$ref": "#/definitions/repo.ItemSummary"
"x-omitempty": true
},
"purchaseFrom": {
"type": "string"
Expand Down Expand Up @@ -2144,9 +2151,13 @@ const docTemplate = `{
},
"location": {
"description": "Edges",
"allOf": [
{
"$ref": "#/definitions/repo.LocationSummary"
}
],
"x-nullable": true,
"x-omitempty": true,
"$ref": "#/definitions/repo.LocationSummary"
"x-omitempty": true
},
"name": {
"type": "string"
Expand All @@ -2170,7 +2181,8 @@ const docTemplate = `{
"type": "boolean"
},
"assetId": {
"type": "string"
"type": "string",
"example": "0"
},
"description": {
"type": "string"
Expand Down Expand Up @@ -2255,7 +2267,6 @@ const docTemplate = `{
"type": "string"
},
"warrantyExpires": {
"description": "Sold",
"type": "string"
}
}
Expand Down Expand Up @@ -2429,7 +2440,6 @@ const docTemplate = `{
"type": "object",
"properties": {
"completedDate": {
"description": "Sold",
"type": "string"
},
"cost": {
Expand All @@ -2446,7 +2456,6 @@ const docTemplate = `{
"type": "string"
},
"scheduledDate": {
"description": "Sold",
"type": "string"
}
}
Expand All @@ -2458,7 +2467,6 @@ const docTemplate = `{
],
"properties": {
"completedDate": {
"description": "Sold",
"type": "string"
},
"cost": {
Expand All @@ -2472,7 +2480,6 @@ const docTemplate = `{
"type": "string"
},
"scheduledDate": {
"description": "Sold",
"type": "string"
}
}
Expand All @@ -2481,7 +2488,6 @@ const docTemplate = `{
"type": "object",
"properties": {
"completedDate": {
"description": "Sold",
"type": "string"
},
"cost": {
Expand All @@ -2495,7 +2501,6 @@ const docTemplate = `{
"type": "string"
},
"scheduledDate": {
"description": "Sold",
"type": "string"
}
}
Expand Down Expand Up @@ -2897,6 +2902,8 @@ var SwaggerInfo = &swag.Spec{
Description: "Track, Manage, and Organize your Things.",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
Expand Down
34 changes: 20 additions & 14 deletions backend/app/api/static/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2030,9 +2030,13 @@
},
"location": {
"description": "Edges",
"allOf": [
{
"$ref": "#/definitions/repo.LocationSummary"
}
],
"x-nullable": true,
"x-omitempty": true,
"$ref": "#/definitions/repo.LocationSummary"
"x-omitempty": true
},
"manufacturer": {
"type": "string"
Expand All @@ -2048,9 +2052,13 @@
"type": "string"
},
"parent": {
"allOf": [
{
"$ref": "#/definitions/repo.ItemSummary"
}
],
"x-nullable": true,
"x-omitempty": true,
"$ref": "#/definitions/repo.ItemSummary"
"x-omitempty": true
},
"purchaseFrom": {
"type": "string"
Expand Down Expand Up @@ -2136,9 +2144,13 @@
},
"location": {
"description": "Edges",
"allOf": [
{
"$ref": "#/definitions/repo.LocationSummary"
}
],
"x-nullable": true,
"x-omitempty": true,
"$ref": "#/definitions/repo.LocationSummary"
"x-omitempty": true
},
"name": {
"type": "string"
Expand All @@ -2162,7 +2174,8 @@
"type": "boolean"
},
"assetId": {
"type": "string"
"type": "string",
"example": "0"
},
"description": {
"type": "string"
Expand Down Expand Up @@ -2247,7 +2260,6 @@
"type": "string"
},
"warrantyExpires": {
"description": "Sold",
"type": "string"
}
}
Expand Down Expand Up @@ -2421,7 +2433,6 @@
"type": "object",
"properties": {
"completedDate": {
"description": "Sold",
"type": "string"
},
"cost": {
Expand All @@ -2438,7 +2449,6 @@
"type": "string"
},
"scheduledDate": {
"description": "Sold",
"type": "string"
}
}
Expand All @@ -2450,7 +2460,6 @@
],
"properties": {
"completedDate": {
"description": "Sold",
"type": "string"
},
"cost": {
Expand All @@ -2464,7 +2473,6 @@
"type": "string"
},
"scheduledDate": {
"description": "Sold",
"type": "string"
}
}
Expand All @@ -2473,7 +2481,6 @@
"type": "object",
"properties": {
"completedDate": {
"description": "Sold",
"type": "string"
},
"cost": {
Expand All @@ -2487,7 +2494,6 @@
"type": "string"
},
"scheduledDate": {
"description": "Sold",
"type": "string"
}
}
Expand Down
17 changes: 7 additions & 10 deletions backend/app/api/static/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ definitions:
description: Warranty
type: boolean
location:
$ref: '#/definitions/repo.LocationSummary'
allOf:
- $ref: '#/definitions/repo.LocationSummary'
description: Edges
x-nullable: true
x-omitempty: true
Expand All @@ -156,7 +157,8 @@ definitions:
description: Extras
type: string
parent:
$ref: '#/definitions/repo.ItemSummary'
allOf:
- $ref: '#/definitions/repo.ItemSummary'
x-nullable: true
x-omitempty: true
purchaseFrom:
Expand Down Expand Up @@ -216,7 +218,8 @@ definitions:
$ref: '#/definitions/repo.LabelSummary'
type: array
location:
$ref: '#/definitions/repo.LocationSummary'
allOf:
- $ref: '#/definitions/repo.LocationSummary'
description: Edges
x-nullable: true
x-omitempty: true
Expand All @@ -235,6 +238,7 @@ definitions:
archived:
type: boolean
assetId:
example: "0"
type: string
description:
type: string
Expand Down Expand Up @@ -295,7 +299,6 @@ definitions:
warrantyDetails:
type: string
warrantyExpires:
description: Sold
type: string
type: object
repo.LabelCreate:
Expand Down Expand Up @@ -410,7 +413,6 @@ definitions:
repo.MaintenanceEntry:
properties:
completedDate:
description: Sold
type: string
cost:
example: "0"
Expand All @@ -422,13 +424,11 @@ definitions:
name:
type: string
scheduledDate:
description: Sold
type: string
type: object
repo.MaintenanceEntryCreate:
properties:
completedDate:
description: Sold
type: string
cost:
example: "0"
Expand All @@ -438,15 +438,13 @@ definitions:
name:
type: string
scheduledDate:
description: Sold
type: string
required:
- name
type: object
repo.MaintenanceEntryUpdate:
properties:
completedDate:
description: Sold
type: string
cost:
example: "0"
Expand All @@ -456,7 +454,6 @@ definitions:
name:
type: string
scheduledDate:
description: Sold
type: string
type: object
repo.MaintenanceLog:
Expand Down
Loading

0 comments on commit 742ece7

Please sign in to comment.