Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Can not use custom types in "One Of" #360

Closed
goganchic opened this issue Jul 13, 2016 · 2 comments
Closed

Can not use custom types in "One Of" #360

goganchic opened this issue Jul 13, 2016 · 2 comments
Labels

Comments

@goganchic
Copy link
Contributor

I'm describing map POI api. So I have api method /map_markers which returns an array of markers. Each marker can be a poi or a cluster. I use such api description

FORMAT: 1A

# Test

# Data Structures

## Poi

+ name (string, required)
+ address (string, required)
+ phone (number, optional)

## Location

+ lon (number, required)
+ lat (number, required)

## MapMarker

+ One Of
    + Properties
        + kind: poi (string, required, fixed)
        + poi (Poi, required)
        + location (Location, required)
    + Properties
        + kind: cluster (string, required, fixed)
        + size (number, required)
        + location (Location, required)

# Group api

## POIs [/map_markers]

### Get POIs list [GET]

+ Response 200 (application/json)
    + Attributes
        + result (array[MapMarker], required, fixed)

but if I use custom type in One Of section (not just a number or string) - json schema will be wrong:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "result": {
      "type": "array",
      "items": [
        {
          "type": "object",
          "properties": {},
          "oneOf": [
            {
              "properties": {
                "kind": {
                  "type": "string",
                  "enum": [
                    "poi"
                  ]
                },
                "poi": {
                  "type": "object",
                  "properties": {}
                },
                "location": {
                  "type": "object",
                  "properties": {}
                }
              }
            },
            {
              "properties": {
                "kind": {
                  "type": "string",
                  "enum": [
                    "cluster"
                  ]
                },
                "size": {
                  "type": "number"
                },
                "location": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          ],
          "additionalProperties": false
        }
      ]
    }
  },
  "required": [
    "result"
  ]
}

Json schema contains empty objects instead of custom types.

@zdne
Copy link
Contributor

zdne commented Jul 13, 2016

Note I've verified this bug with this minimal blueprint:

# GET /ab
- response 200 (application/json)
    - Attributes (A or B)

# Data Structures

## A or B
- One Of
    - Properties
        - text: A (string)
        - somevalue (C)

    - Properties
        - text: B (string)

## C
- c1: C1

@zdne zdne added the bug label Jul 13, 2016
@goganchic
Copy link
Contributor Author

I think that problem in a drafter, not in a snowcrash. IsExpandableVisitor do not process options of select kind, so for select (One Of) element it always tells that object is not expandable. ExpandVisitor has no code to expand select element, so it rendered as is without any modifications.

goganchic added a commit to goganchic/drafter that referenced this issue Jul 16, 2016
goganchic added a commit to goganchic/drafter that referenced this issue Jul 17, 2016
goganchic added a commit to goganchic/drafter that referenced this issue Jul 17, 2016
goganchic added a commit to goganchic/drafter that referenced this issue Jul 18, 2016
goganchic added a commit to goganchic/drafter that referenced this issue Jul 18, 2016
pksunkara added a commit that referenced this issue Jul 18, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants