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

Maintain generated JSON schema file name casing from OpenAPI definitions #20

Open
heilaaks opened this issue Jan 10, 2019 · 0 comments
Open

Comments

@heilaaks
Copy link

Description

Generated JSON schema files are converted to all lowercase file names. This can break JSON schema references if capital letters are used in OpenAPI reference names.

Expected behavior

Maintain the same casing for generated JSON schema file names as defined in OpenAPI definitions.

Steps to reproduce

# Requires Go version 1.11 to use Go modules.
pip install openapi2jsonschema==0.8.0
openapi2jsonschema schema.yaml -o output
go mod init github.com/random/testing
go build schema.go
./schema
compile error: open /<full-file-path>/output/RequestData.json: no such file or directory
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x6e8558]

goroutine 1 [running]:
github.com/xeipuuv/gojsonschema.(*Schema).validateDocument(0x0, 0x746e40, 0xc0000934a0, 0x0)
        /root/go/pkg/mod/github.com/xeipuuv/[email protected]/validation.go:72 +0x78
github.com/xeipuuv/gojsonschema.(*Schema).Validate(0x0, 0x80f880, 0xc00008f880, 0x1, 0x1, 0x63)
        /root/go/pkg/mod/github.com/xeipuuv/[email protected]/validation.go:64 +0x6b
main.main()
        /<full-file-path/schema.go:13 +0x1cb
// schema.go
//
// Modify the full file path below to point to generated all.json file.

package main

import (
        "fmt"
        "github.com/xeipuuv/gojsonschema"
)

func main() {
        sl := gojsonschema.NewSchemaLoader()
        schema, err := sl.Compile(
                gojsonschema.NewReferenceLoader("file:///<full-file-path>/output/all.json"))
        fmt.Printf("compile error: %s\n", err)
        document := gojsonschema.NewStringLoader(`{"type": "string"}`)
        result, err := schema.Validate(document)
        if result.Valid() {
                fmt.Printf("document is valid\n")
        } else {
                fmt.Printf("document is not valid\n")
        }
}
# schema.yaml

openapi: 3.0.0
servers:
  - url: /app/v1
info:
  version: "1.0-oas3"
  title: Testing JSON schema generation
paths:
  '/items':
    post:
      summary: post
      requestBody:
        $ref: '#/components/requestBodies/RequestCollection'
      responses:
        '500':
          $ref: '#/components/responses/500'
components:
  schemas:
    RequestCollection:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/RequestData'
      required:
        - data
    RequestData:
      type: object
      properties:
        type:
          type: string
        attributes:
          $ref: '#/components/schemas/Attributes'
    Attributes:
      type: object
      properties:
        name:
          type: string
    Errors:
      type: object
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/Error'
    Error:
      type: object
      properties:
        status:
          type: string
      required:
        - status
  responses:
    '500':
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Errors'
  requestBodies:
    RequestCollection:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RequestCollection'
      required: true
zeusttu added a commit to zeusttu/openapi2jsonschema that referenced this issue May 3, 2019
lirik90 pushed a commit to lirik90/swagger2jsonschema that referenced this issue Apr 1, 2024
Include schemas from:

paths/<path>/<httpmethod>/requestBody/content/<mimetype>/schema
paths/<path>/<httpmethod>/responses/<httpcode>/content/<mimetype>/schema

Closes instrumenta#25

Do not downcase filenames

Closes instrumenta#20

Move new functionality to separate function

Make "content" key in body definition optional

This was committed as a GitHub review suggestion.
Commit message suggested by Github:

Update openapi2jsonschema/util.py

Co-authored-by: Adam Kitain <[email protected]>
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