instrumenta / instrumenta/openapi2jsonschema

Maintain generated JSON schema file name casing from OpenAPI definitions

Open
#20 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
248
Forks
95
PR merge metrics
No merged PRs in 30d

Description

### 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 //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/gojsonschema@v1.1.0/validation.go:72 +0x78
github.com/xeipuuv/gojsonschema.(*Schema).Validate(0x0, 0x80f880, 0xc00008f880, 0x1, 0x1, 0x63)
/root/go/pkg/mod/github.com/xeipuuv/gojsonschema@v1.1.0/validation.go:64 +0x6b
main.main()
//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
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.