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

expected 'IDENT', found 'import' #36

Open
a-h opened this issue Jul 15, 2016 · 2 comments
Open

expected 'IDENT', found 'import' #36

a-h opened this issue Jul 15, 2016 · 2 comments

Comments

@a-h
Copy link

a-h commented Jul 15, 2016

When attempting to generate Go structs with this schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {
    "address": {
      "id": "address",
      "type": "object",
      "description": "Address",
      "properties": {
        "houseName": {
          "type": "string",
          "description": "House Name",
          "maxLength": 30
        },
        "houseNumber": {
          "type": "string",
          "description": "House Number",
          "maxLength": 4
        },
        "flatNumber": {
          "type": "string",
          "description": "Flat",
          "maxLength": 15
        },
        "street": {
          "type": "string",
          "description": "Address 1",
          "maxLength": 40
        },
        "district": {
          "type": "string",
          "description": "Address 2",
          "maxLength": 30
        },
        "town": {
          "type": "string",
          "description": "City",
          "maxLength": 20
        },
        "county": {
          "type": "string",
          "description": "County",
          "maxLength": 20
        },
        "postcode": {
          "type": "string",
          "description": "Postcode",
          "maxLength": 8
        }
      }
    },
    "status": {
      "type": "object",
      "properties": {
        "favouritecat": {
          "enum": [
            "A",
            "B",
            "C",
            "D",
            "E",
            "F"
          ],
          "type": "string",
          "description": "The favourite cat.",
          "maxLength": 1
        }
      }
    }
  },
  "properties": {
    "name": {
      "type": "string"
    },
    "address": {
      "$ref": "#/definitions/address"
    },
    "status": {
      "$ref": "#/definitions/status"
    }
  }
}

Using this command line:

./schematic ~/goprojects/src/github.com/a-h/schemagenerators/exampleschema.json

The following error is returned:

schematic: 12:5: expected 'IDENT', found 'import'
@stevenroose
Copy link

I get the same error. I can't give away the whole schema file, but it's not more complex than this:

{
  "$schema": "http://json-schema.org/schema#",

  "id": "http://some-domain.org/someschema.json#",
  "description": "A JSON schema for  ...",

  "type": "object",
  "properties": {

    "field1": {
      "description": "time indicator",
      "type": "string",
      "maxLength": 9,
      "_comment": "some comment"
    },

    "field2": {
      "description": "...",
      "type": "string",
      "minLength": 10,
      "maxLength": 24,
      "pattern": "^[0-9]{6}[A-Za-z]{3}[0-9]{1,15}(.[0-9]{1-15})?$"
    },
  },
  "required": ["field1", "field2"],
  "additionalProperties": false
}

I used ajv and an online verification tool and the format is valid according to both.

@gnur
Copy link

gnur commented Mar 18, 2019

I found out that the JSON schema needs a title field for schematic to work

{
   "title": "this-becomes-your-go-package-name",
   //rest of the schema
}

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

3 participants