Skip to content

Commit

Permalink
hosted ghc v2 swagger ui with some ref errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cameroncaci committed Jan 31, 2024
1 parent 67bbec7 commit 9b0790d
Show file tree
Hide file tree
Showing 4 changed files with 353 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/milmove/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ func initializeRouteOptions(v *viper.Viper, routingConfig *routing.Config) {
routingConfig.ServeGHC = v.GetBool(cli.ServeGHCFlag)
if routingConfig.ServeGHC {
routingConfig.GHCSwaggerPath = v.GetString(cli.GHCSwaggerFlag)
routingConfig.GHCV2SwaggerPath = v.GetString(cli.GHCV2SwaggerFlag)
}
routingConfig.ServeDevlocalAuth = v.GetBool(cli.DevlocalAuthFlag)

Expand Down
4 changes: 4 additions & 0 deletions pkg/cli/swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
AdminSwaggerFlag string = "admin-swagger"
// GHCSwaggerFlag is the GHC Swagger Flag
GHCSwaggerFlag string = "ghc-swagger"
// GHCV2SwaggerFlag is the GHC Swagger Flag
GHCV2SwaggerFlag string = "ghc-v2-swagger"
// PrimeSwaggerFlag is the Prime Swagger Flag
PrimeSwaggerFlag string = "prime-swagger"
// PrimeV2SwaggerFlag is the Prime V2 Swagger Flag
Expand All @@ -34,6 +36,7 @@ func InitSwaggerFlags(flag *pflag.FlagSet) {
flag.String(OrdersSwaggerFlag, "swagger/orders.yaml", "The location of the Orders API swagger definition")
flag.String(AdminSwaggerFlag, "swagger/admin.yaml", "The location of the admin API swagger definition")
flag.String(GHCSwaggerFlag, "swagger/ghc.yaml", "The location of the GHC API swagger definition")
flag.String(GHCV2SwaggerFlag, "swagger/ghc_v2.yaml", "The location of the GHC V2 API swagger definition")
flag.String(PrimeSwaggerFlag, "swagger/prime.yaml", "The location of the Prime API swagger definition")
flag.String(PrimeV2SwaggerFlag, "swagger/prime_v2.yaml", "The location of the Prime V2 API swagger definition")
flag.Bool(ServeSwaggerUIFlag, false, "Whether to serve swagger UI for the APIs")
Expand All @@ -46,6 +49,7 @@ func CheckSwagger(v *viper.Viper) error {
InternalSwaggerFlag,
OrdersSwaggerFlag,
GHCSwaggerFlag,
GHCV2SwaggerFlag,
AdminSwaggerFlag,
PrimeSwaggerFlag,
PrimeV2SwaggerFlag,
Expand Down
27 changes: 27 additions & 0 deletions pkg/handlers/routing/routing_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ type Config struct {
ServeGHC bool
// The path to the ghc api swagger definition
GHCSwaggerPath string
// The path to the ghc v2 api swagger definition
GHCV2SwaggerPath string

// Should devlocal auth be enabled? Definitely never enabled in
// production
Expand Down Expand Up @@ -537,6 +539,31 @@ func mountGHCAPI(appCtx appcontext.AppContext, routingConfig *Config, site chi.R
r.Method("GET", "/docs", http.NotFoundHandler())
}

// Mux for GHC API that enforces auth
r.Route("/", func(rAuth chi.Router) {
rAuth.Use(userAuthMiddleware)
rAuth.Use(addAuditUserToRequestContextMiddleware)
rAuth.Use(middleware.NoCache())
api := ghcapi.NewGhcAPIHandler(routingConfig.HandlerConfig)
permissionsMiddleware := authentication.PermissionsMiddleware(appCtx, api)
rAuth.Use(permissionsMiddleware)
tracingMiddleware := middleware.OpenAPITracing(api)
rAuth.Mount("/", api.Serve(tracingMiddleware))
})
})
site.Route("/ghc/v2", func(r chi.Router) {
r.Method("GET", "/swagger.yaml",
handlers.NewFileHandler(routingConfig.FileSystem,
routingConfig.GHCV2SwaggerPath))
if routingConfig.ServeSwaggerUI {
appCtx.Logger().Info("GHC API Swagger UI serving is enabled")
r.Method("GET", "/docs",
handlers.NewFileHandler(routingConfig.FileSystem,
path.Join(routingConfig.BuildRoot, "swagger-ui", "ghc.html")))
} else {
r.Method("GET", "/docs", http.NotFoundHandler())
}

// Mux for GHC API that enforces auth
r.Route("/", func(rAuth chi.Router) {
rAuth.Use(userAuthMiddleware)
Expand Down
321 changes: 321 additions & 0 deletions swagger/ghc_v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
swagger: "2.0"
info:
title: MilMove GHC V2 API
license:
name: MIT
url: 'https://opensource.org/licenses/MIT'
contact:
email: milmove-developers@caci.com
description: >
The GHC V2 API is a RESTful API that enables the Office application for MilMove.
All endpoints are located under `/ghc/v2`.
version: 0.0.1
basePath: /ghc/v2
schemes:
- https
paths:
'/move_task_orders/{moveTaskOrderID}/mto_shipments/{shipmentID}':
patch:
summary: updateMTOShipment
description: |
Updates a specified MTO shipment.
Required fields include:
* MTO Shipment ID required in path
* If-Match required in headers
* No fields required in body
Optional fields include:
* New shipment status type
* Shipment Type
* Customer requested pick-up date
* Pick-up Address
* Delivery Address
* Secondary Pick-up Address
* SecondaryDelivery Address
* Delivery Address Type
* Customer Remarks
* Counselor Remarks
* Releasing / Receiving agents
consumes:
- application/json
produces:
- application/json
operationId: updateMTOShipment
tags:
- mtoShipment
parameters:
- in: path
name: moveTaskOrderID
required: true
format: uuid
type: string
description: ID of move task order for mto shipment to use
- in: path
name: shipmentID
type: string
format: uuid
required: true
description: UUID of the MTO Shipment to update
- in: header
name: If-Match
type: string
required: true
description: >
Optimistic locking is implemented via the `If-Match` header. If the ETag header does not match
the value of the resource on the server, the server rejects the change with a `412 Precondition Failed` error.
- in: body
name: body
schema:
$ref: '#/definitions/UpdateShipment'
responses:
'200':
description: Successfully updated the specified MTO shipment.
schema:
$ref: 'definitions/MTOShipment.yaml'
'400':
$ref: '#/responses/InvalidRequest'
'401':
$ref: '#/responses/PermissionDenied'
'403':
$ref: '#/responses/PermissionDenied'
'404':
$ref: '#/responses/NotFound'
'412':
$ref: '#/responses/PreconditionFailed'
'422':
$ref: '#/responses/UnprocessableEntity'
'500':
$ref: '#/responses/ServerError'
definitions:
UpdateShipment:
type: object
properties:
shipmentType:
$ref: 'definitions/MTOShipmentType.yaml'
requestedPickupDate:
format: date
type: string
x-nullable: true
requestedDeliveryDate:
format: date
type: string
x-nullable: true
customerRemarks:
type: string
example: handle with care
x-nullable: true
counselorRemarks:
type: string
example: counselor approved
x-nullable: true
billableWeightCap:
type: integer
description: estimated weight of the shuttle service item provided by the prime
example: 2500
x-formatting: weight
x-nullable: true
billableWeightJustification:
type: string
example: more weight than expected
x-nullable: true
pickupAddress:
allOf:
- $ref: 'definitions/Address.yaml'
destinationAddress:
allOf:
- $ref: 'definitions/Address.yaml'
secondaryDeliveryAddress:
allOf:
- $ref: 'definitions/Address.yaml'
secondaryPickupAddress:
allOf:
- $ref: 'definitions/Address.yaml'
hasSecondaryPickupAddress:
type: boolean
x-nullable: true
x-omitempty: false
hasSecondaryDeliveryAddress:
type: boolean
x-nullable: true
x-omitempty: false
destinationType:
$ref: 'definitions/DestinationType.yaml'
agents:
$ref: 'definitions/MTOAgents.yaml'
x-nullable: true
tacType:
$ref: 'definitions/LOATypeNullable.yaml'
sacType:
$ref: 'definitions/LOATypeNullable.yaml'
usesExternalVendor:
type: boolean
example: false
x-nullable: true
serviceOrderNumber:
type: string
x-nullable: true
ntsRecordedWeight:
description: The previously recorded weight for the NTS Shipment. Used for NTS Release to know what the previous primeActualWeight or billable weight was.
example: 2000
type: integer
x-formatting: weight
x-nullable: true
storageFacility:
x-nullable: true
$ref: 'definitions/StorageFacility.yaml'
ppmShipment:
$ref: '#/definitions/UpdatePPMShipment'
UpdatePPMShipment:
type: object
properties:
expectedDepartureDate:
description: >
Date the customer expects to move.
format: date
type: string
x-nullable: true
actualMoveDate:
format: date
type: string
x-nullable: true
pickupPostalCode:
description: zip code
format: zip
type: string
title: ZIP
example: '90210'
pattern: ^(\d{5})$
x-nullable: true
secondaryPickupPostalCode:
format: zip
type: string
title: ZIP
example: '90210'
pattern: ^(\d{5})$
x-nullable: true
destinationPostalCode:
format: zip
type: string
title: ZIP
example: '90210'
pattern: ^(\d{5})$
x-nullable: true
secondaryDestinationPostalCode:
format: zip
type: string
title: ZIP
example: '90210'
pattern: ^(\d{5})$
x-nullable: true
w2Address:
x-nullable: true
$ref: 'definitions/Address.yaml'
sitExpected:
type: boolean
x-nullable: true
sitLocation:
allOf:
- $ref: 'definitions/SITLocationType.yaml'
- x-nullable: true
sitEstimatedWeight:
type: integer
example: 2000
x-nullable: true
sitEstimatedEntryDate:
format: date
type: string
x-nullable: true
sitEstimatedDepartureDate:
format: date
type: string
x-nullable: true
estimatedWeight:
type: integer
example: 4200
x-nullable: true
hasProGear:
description: >
Indicates whether PPM shipment has pro gear.
type: boolean
x-nullable: true
proGearWeight:
type: integer
x-nullable: true
spouseProGearWeight:
type: integer
x-nullable: true
hasRequestedAdvance:
description: >
Indicates whether an advance has been requested for the PPM shipment.
type: boolean
x-nullable: true
advanceAmountRequested:
description: >
The amount request for an advance, or null if no advance is requested
type: integer
format: cents
x-nullable: true
advanceStatus:
$ref: 'definitions/PPMAdvanceStatus.yaml'
x-nullable: true
Error:
properties:
message:
type: string
required:
- message
type: object
ValidationError:
allOf:
- $ref: '#/definitions/ClientError'
- type: object
properties:
invalid_fields:
type: object
additionalProperties:
type: string
required:
- invalid_fields
ClientError:
type: object
properties:
title:
type: string
detail:
type: string
instance:
type: string
format: uuid
required:
- title
- detail
- instance
responses:
InvalidRequest:
description: The request payload is invalid
schema:
$ref: '#/definitions/Error'
NotFound:
description: The requested resource wasn't found
schema:
$ref: '#/definitions/Error'
Conflict:
description: Conflict error
schema:
$ref: '#/definitions/Error'
PermissionDenied:
description: The request was denied
schema:
$ref: '#/definitions/Error'
ServerError:
description: A server error occurred
schema:
$ref: '#/definitions/Error'
PreconditionFailed:
description: Precondition failed
schema:
$ref: '#/definitions/Error'
UnprocessableEntity:
description: The payload was unprocessable.
schema:
$ref: '#/definitions/ValidationError'

0 comments on commit 9b0790d

Please sign in to comment.