sukovanej / effect-http

Declarative HTTP API library for effect-ts
https://sukovanej.github.io/effect-http
MIT License
252 stars 20 forks source link

Authorize swagger button doesn't appear any more #646

Closed kattsushi closed 3 months ago

kattsushi commented 3 months ago
Screenshot 2024-08-03 at 10 50 33 a m Screenshot 2024-08-03 at 11 03 53 a m

since some previous versions the Authorize swagger button it doesnt appear any more to setup the bearer token

here my implementation for reference

export const authSecurity = pipe(
  Security.bearer({ name: 'AuthToken', description: 'token', bearerFormat: 'JWT' }),
  Security.mapEffect((creds) => {
    if (creds === 'secret') {
      return T.succeed(creds)
    }
    return HttpError.unauthorized('Invalid token')
  }),
)

export const createUserEndpoint = Api.post('createUser', '/api/users').pipe(
  Api.setRequestBody(UserWithOutId),
  Api.setResponseBody(User),
  Api.setSecurity(authSecurity),
)

export const UserApiGroup = ApiGroup.make('Users', {
  description: 'All about Users',
}).pipe(
  ApiGroup.addEndpoint(createUserEndpoint),
)

export const GatewayApi = Api.make({
  title: 'API Gateway',
  servers: [{ url: 'http://localhost:3001' }],
}).pipe(
  Api.addGroup(UserApiGroup),
)

export const GatewayRouterBuilder = RouterBuilder.make(GatewayApi, {
  docsPath: '/api',
  parseOptions: { errors: 'all' },
}).pipe(
  RouterBuilder.merge(UserRouterBuilder),
  RouterBuilder.build,
  Middlewares.errorLog,
)

const ApiLayer = pipe(
  Layer.mergeAll(PrettyLogger.layer(), DotEnv.setConfigProvider()),
  Layer.provideMerge(NodeContext.layer),
  OpenTelemetryLayer({ serviceName: 'Api Gateway' }),
)

const main = pipe(
  EnvConfig,
  T.tap((config) => T.logInfo(`Starting Api Gateway... visit http://localhost:${config.port}/api to see the docs`)),
  T.flatMap((config) => GatewayRouterBuilder.pipe(NodeServer.listen({ port: config.port }))),
  T.provide(ApiLayer),
  Logger.withMinimumLogLevel(LogLevel.All),
)

runMain(main)
sukovanej commented 3 months ago

Hey, I tried adjusting the code snippet you shared so I can run it and I can't reproduce. Please, share a minimal repro or a snippet that compiles.

kattsushi commented 3 months ago

sure here is the stackblitz for the repo https://stackblitz.com/edit/stackblitz-starters-8bptu2?file=index.ts

Screenshot 2024-08-03 at 4 23 09 p m

also i realized that at the botton-right appears an ivalid note, im not sure if is releated

but clicking says this error

{
  "schemaValidationMessages": [
    {
      "level": "error",
      "message": "Can't read from file https://stackblitzstarters8bptu2-cdb4--3000--41692973.local-credentialless.webcontainer.io/api/openapi.json"
    }
  ]
}
Screenshot 2024-08-03 at 4 24 58 p m
sukovanej commented 3 months ago

Hey, fix released. Thank you, nice catch!