Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated swagger may have undefined references #224

Open
kaol opened this issue Apr 28, 2021 · 0 comments
Open

Generated swagger may have undefined references #224

kaol opened this issue Apr 28, 2021 · 0 comments

Comments

@kaol
Copy link

kaol commented Apr 28, 2021

It's possible for a Swagger spec to have undefined references. The following check returns a nonempty list if that happens. Any such swagger spec will cause trouble with any tools trying to use it. I'm not quite sure where it would fit in Data.Swagger.Schema.Validation as those concern validating data against a spec but this is about the validity of the spec itself.

Here's an example of a faulty Swagger file. I'm afraid it's not a minimal example. Running openapi-spec-validator --schema 2.0 on it gives an error Unresolvable JSON pointer: 'definitions/PaperCode'. I didn't see that swagger2 library had any call that would have given the same information about it.

import Control.Lens
import qualified Data.Set as Set
import Data.Swagger
import qualified Data.HashMap.Strict.InsOrd as InsOrd

missingRefs :: Swagger -> Bool
missingRegs swagger = Set.null $ Set.difference usedRefs swaggerDefinitions
  where
    usedRefs = Set.fromList . catMaybes . map getRef . concatMap (toList . view properties) . toList $ swagger ^. definitions
    getRef (Inline _) = Nothing
    getRef (Ref r) = Just $ getReference r
    swaggerDefinitions = Set.fromList . map fst . InsOrd.toList $ swagger ^. definitions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant