Skip to content

Commit

Permalink
Merge pull request #460 from tdakkota/feat/yaml-location
Browse files Browse the repository at this point in the history
feat(ogen): parse correct line number for YAML
  • Loading branch information
ernado authored Jul 7, 2022
2 parents ae203f1 + 0080531 commit 6a6d8e0
Show file tree
Hide file tree
Showing 28 changed files with 2,072 additions and 1,484 deletions.
61 changes: 61 additions & 0 deletions _testdata/location/location_spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"openapi": "3.0.3",
"info": {
"title": "WARNING: Update TestLocation if you change this file",
"version": "0.1.0"
},
"paths": {
"/foo": {
"post": {
"parameters": [
{
"name": "foo",
"in": "query",
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
},
"responses": {
"200": {
"description": "User info",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"User": {
"type": "object",
"properties": {
"name": {
"type": "integer",
"enum": [
1,
2,
3
],
"minimum": 2
}
}
}
}
}
}
36 changes: 36 additions & 0 deletions _testdata/location/location_spec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
openapi: 3.0.3
info:
title: 'WARNING: Update TestLocation if you change this file'
version: 0.1.0
paths:
/foo:
post:
parameters:
- name: foo
in: query
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/User'
responses:
"200":
description: User info
content:
application/json:
schema:
$ref: '#/components/schemas/User'
components:
schemas:
User:
type: object
properties:
name:
type: integer
enum:
- 1
- 2
- 3
minimum: 2
4 changes: 2 additions & 2 deletions dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ func (s *Schema) SetMinProperties(m *uint64) *Schema {

// SetDefault sets the Default of the Schema.
func (s *Schema) SetDefault(d jsonv1.RawMessage) *Schema {
s.Default = jsonv2.RawValue(d)
s.Default = Default(d)
return s
}

Expand Down Expand Up @@ -1032,7 +1032,7 @@ func (s *Schema) AsArray() *Schema {
func (s *Schema) AsEnum(def jsonv1.RawMessage, values ...jsonv1.RawMessage) *Schema {
return &Schema{
Type: s.Type,
Default: jsonv2.RawValue(def),
Default: Default(def),
Enum: func() (r []jsonv2.RawValue) {
for _, val := range values {
r = append(r, jsonv2.RawValue(val))
Expand Down
3 changes: 2 additions & 1 deletion dsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ogen-go/ogen"
"github.com/ogen-go/ogen/gen/ir"
"github.com/ogen-go/ogen/jsonschema"
)

const (
Expand Down Expand Up @@ -374,7 +375,7 @@ func TestBuilder(t *testing.T) {
UniqueItems: true,
MaxProperties: &umax,
MinProperties: &umax,
Default: jsonv2.RawValue("0"),
Default: jsonschema.Default("0"),
}, ogen.NewSchema().
SetRef("ref").
SetDescription("desc").
Expand Down
Loading

0 comments on commit 6a6d8e0

Please sign in to comment.