• Home
  • Raw
  • Download

Lines Matching +full:object +full:- +full:schema

7 #      http://www.apache.org/licenses/LICENSE-2.0
15 """Schema processing for discovery based APIs
17 Schemas holds an APIs discovery schemas. It can return those schema as
19 conform to the schema.
21 For example, given the schema:
23 schema = \"\"\"{
25 "type": "object",
45 s = Schemas(schema)
57 The constructor takes a discovery document in which to look up named schema.
70 class Schemas(object):
77 discovery: object, Deserialized discovery document from which we pull
78 out the named schema.
87 """Get pretty printed object prototype from the schema name.
90 name: string, Name of schema in the discovery document.
91 seen: list of string, Names of schema already seen. Used to handle
95 string, A string that contains a prototype object with
96 comments that conforms to the given schema.
103 return "# Object with schema name: %s" % name
116 """Get pretty printed object prototype from the schema name.
119 name: string, Name of schema in the discovery document.
122 string, A string that contains a prototype object with
123 comments that conforms to the given schema.
126 return self._prettyPrintByName(name, seen=[], dent=0)[:-2]
129 def _prettyPrintSchema(self, schema, seen=None, dent=0): argument
130 """Get pretty printed object prototype of schema.
133 schema: object, Parsed JSON schema.
134 seen: list of string, Names of schema already seen. Used to handle
138 string, A string that contains a prototype object with
139 comments that conforms to the given schema.
144 return _SchemaToStruct(schema, seen, dent=dent).to_str(self._prettyPrintByName)
146 def prettyPrintSchema(self, schema): argument
147 """Get pretty printed object prototype of schema.
150 schema: object, Parsed JSON schema.
153 string, A string that contains a prototype object with
154 comments that conforms to the given schema.
157 return self._prettyPrintSchema(schema, dent=0)[:-2]
160 """Get deserialized JSON schema from the schema name.
163 name: string, Schema name.
164 default: object, return value if name not found.
169 class _SchemaToStruct(object):
170 """Convert schema to a prototype object."""
173 def __init__(self, schema, seen, dent=0): argument
177 schema: object, Parsed JSON schema.
178 seen: list, List of names of schema already seen while parsing. Used to
188 # The parsed JSON schema.
189 self.schema = schema
194 # Method that when called returns a prototype object for the schema with
198 # List of names of schema already seen while parsing.
239 self.dent -= 1
241 def _to_str_impl(self, schema): argument
242 """Prototype object based on the schema, in Python code with comments.
245 schema: object, Parsed JSON schema file.
248 Prototype object based on the schema, in Python code with comments.
250 stype = schema.get("type")
251 if stype == "object":
252 self.emitEnd("{", schema.get("description", ""))
254 if "properties" in schema:
255 properties = schema.get("properties", {})
260 elif "additionalProperties" in schema:
262 self._to_str_impl(schema["additionalProperties"])
265 elif "$ref" in schema:
266 schemaName = schema["$ref"]
267 description = schema.get("description", "")
274 value = schema.get("default", "True or False")
275 self.emitEnd("%s," % str(value), schema.get("description", ""))
277 value = schema.get("default", "A String")
278 self.emitEnd('"%s",' % str(value), schema.get("description", ""))
280 value = schema.get("default", "42")
281 self.emitEnd("%s," % str(value), schema.get("description", ""))
283 value = schema.get("default", "3.14")
284 self.emitEnd("%s," % str(value), schema.get("description", ""))
286 self.emitEnd("None,", schema.get("description", ""))
288 self.emitEnd('"",', schema.get("description", ""))
290 self.emitEnd("[", schema.get("description"))
293 self._to_str_impl(schema["items"])
304 """Prototype object based on the schema, in Python code with comments.
307 from_cache: callable(name, seen), Callable that retrieves an object
308 prototype for a schema with the given name. Seen is a list of schema
309 names already seen as we recursively descend the schema definition.
312 Prototype object based on the schema, in Python code with comments.
316 return self._to_str_impl(self.schema)