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

JSON schema export #901

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions pkg/cmd/template/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (o *Options) RunWithFiles(in Input, ui ui.UI) Output {
if err != nil {
return Output{Err: err}
}
if schemaType == RegularFilesOutputTypeOpenAPI {
if schemaType == RegularFilesOutputTypeOpenAPI || schemaType == RegularFilesOutputTypeJSONSchema {
return Output{Err: fmt.Errorf("Output type currently only supported for data values schema (i.e. include --data-values-schema-inspect)")}
}

Expand Down Expand Up @@ -190,8 +190,16 @@ func (o *Options) inspectSchema(dataValuesSchema *datavalues.Schema) Output {
},
}
}
return Output{Err: fmt.Errorf("Data values schema export only supported in OpenAPI v3 format; specify format with --output=%s flag",
RegularFilesOutputTypeOpenAPI)}
if format == RegularFilesOutputTypeJSONSchema {
jsonSchemaDoc := schema.NewJSONSchemaDocument(dataValuesSchema.GetDocumentType())
return Output{
DocSet: &yamlmeta.DocumentSet{
Items: []*yamlmeta.Document{jsonSchemaDoc.AsDocument()},
},
}
}
return Output{Err: fmt.Errorf("Data values schema export only supported in OpenAPI v3 and JSON Schema format; specify format with --output=(%s|%s) flag",
RegularFilesOutputTypeOpenAPI, RegularFilesOutputTypeJSONSchema)}
}

func (o *Options) pickSource(srcs []FileSource, pickFunc func(FileSource) bool) FileSource {
Expand Down
7 changes: 4 additions & 3 deletions pkg/cmd/template/regular_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,15 @@ const (

// When the FileSource are RegularFilesSource, indicates which schema type to use when rendering the output.
const (
RegularFilesOutputTypeOpenAPI = "openapi-v3"
RegularFilesOutputTypeNone = ""
RegularFilesOutputTypeOpenAPI = "openapi-v3"
RegularFilesOutputTypeJSONSchema = "json-schema"
RegularFilesOutputTypeNone = ""
)

// Collections of each category of output type
var (
RegularFilesOutputFormatTypes = []string{RegularFilesOutputTypeYAML, RegularFilesOutputTypeJSON, RegularFilesOutputTypePos}
RegularFilesOutputSchemaTypes = []string{RegularFilesOutputTypeOpenAPI}
RegularFilesOutputSchemaTypes = []string{RegularFilesOutputTypeOpenAPI, RegularFilesOutputTypeJSONSchema}
RegularFilesOutputTypes = append(RegularFilesOutputFormatTypes, RegularFilesOutputSchemaTypes...)
)

Expand Down
Loading
Loading