Skip to content

openapi, contract, and errors in middleware #447

Answered by unnoq
stuartin asked this question in Q&A
Discussion options

You must be logged in to vote

You can reduce duplication when defining oo.spec() like this:

import { oc } from '@orpc/contract'

const publicContractBuilder = oc

const authedContractBuilder = publicContractBuilder.errors({
  UNAUTHORIZED: oo.spec({}, {
    security: authDocs.security
  })
})

Now, any contract built using authedContractBuilder will automatically include the UNAUTHORIZED error and apply authDocs.security as its security scheme.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@stuartin
Comment options

@unnoq
Comment options

Answer selected by stuartin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants