JSON schema definitions validation for internal reference - node.js

I am creating thousands of definitions and making it available on remote so that any one can reuse the defined schema by referring remote ref. at the time of definition creation i want something which can check the $ref and throw error if it is not available
{
"definitions":{
"description100Type":{
"$ref":"#/definitions/additinalType"
}
},
"$schema":"http://json-schema.org/draft-07/schema#",
"$id":"http://example.com/root.json"
}
In the above example description100Type referring additinalType which was not defined.
How to validate the above case ? i am using ajv for validations.
note:ajv is throwing proper error if description100Type is referred inside properties
{
"properties":{
"checked":{
"$id":"#/properties/checked",
"$ref":"#/definitions/description100Type"
}
}
}

Related

Azure Bicep - Subresource reference with resourceId()

I am deploying an App Gateway on Azure using a Bicep template (relevant pieces shown below).
var applicationGatewayId = resourceId('Microsoft.Network/applicationGateways', applicationGatewayName)
resource applicationGateway 'Microsoft.Network/applicationGateways#2021-08-01' = {
properties: {
urlPathMaps: [
{
properties: {
defaultBackendAddressPool: {
id: '${applicationGatewayId}/backendAddressPools/backendpool-test'
}
}
]
}
}
My question is about the id of the backendAddressPool in the example. I get a warning when compiling: Warning use-resource-id-functions: If property "id" represents a resource ID, it must use a symbolic resource reference, be a parameter or start with one of these functions: extensionResourceId, guid, if, reference, resourceId, subscription, subscriptionResourceId, tenantResourceId. [https://aka.ms/bicep/linter/use-resource-id-functions].
I tried using ${applicationGateway.id}/backendAddressPools/backendpool-test, but that results in a cyclic reference error. For other resource types I used resourceId(), but for this example I wouldn't know how to.
I tried, e.g., resourceId('Microsoft.Network/ApplicationGatewayBackendAddressPool', '${prefix}-backendpool-infocat'), but that seems to result in a different resource type altogether (doesn't compile into the same id, at least).
This question is applicable to other subresources too, such as:
applicationGateway.urlPathMaps.defaultBackendAddressPool
applicationGateway.urlPathMaps.pathRules.backendAddressPool
applicationGateway.urlPathMaps.pathRules.backendHttpSettings
...
So how does one refer to these subresources properly, when there's no readily defined resourceType to be used in resourceId()? Can the warnings be avoided?
Thanks in advance!
Try this:
id:resourceId('Microsoft.Network/applicationGateways/backendAddressPools', applicationGatewayName, applicationGatewayBackendAddressPoolName)

How to build a Graqhql mutation with existing variables

This might seem like an odd question, or something really straightforward, but honestly I am struggling to figure out how to do this. I am working in Node.js and I want to set data I have saved on a node object into my GraphQL mutation.
I'm working with a vendor's GraqhQL API, so this isn't something I have created myself, nor do I have a schema file for it. I'm building a mutation that will insert a record into their application, and I can write out everything manually and use a tool like Postman to manually create a new record...the structure of the mutation is not my problem.
What I'm struggling to figure out is how to build the mutation with variables from my node object without just catting a bunch of strings together.
For example, this is what I'm trying to avoid:
class MyClass {
constructor() {
this.username = "my_username"
this.title = "Some Title"
}
}
const obj = new MyClass()
let query = "mutation {
createEntry( input: {
author: { username: \"" + obj.username + "\" }
title: \"" + obj.title + "\"
})
}"
I've noticed that there are a number of different node packages out there for working with Graphql, but none of their documentation that I've seen really addresses the above situation. I've been completely unsuccessful in my Googling attempts, can someone please point me in the right direction? Is there a package out there that's useful for just building queries without requiring a schema or trying to send them at the same time?
GraphQL services typically implement this spec when using HTTP as a transport. That means you can construct a POST request with four parameters:
query - A Document containing GraphQL Operations and Fragments to execute.
operationName - (Optional): The name of the Operation in the Document to execute.
variables - (Optional): Values for any Variables defined by the Operation.
extensions - (Optional): This entry is reserved for implementors to extend the protocol however they see fit.
You can use a Node-friendly version of fetch like cross-fetch, axios, request or any other library of your choice to make the actual HTTP request.
If you have dynamic values you want to substitute inside the query, you should utilize variables to do so. Variables are defined as part of your operation definition at the top of the document:
const query = `
mutation ($input: SomeInputObjectType!) {
createEntry(input: $input) {
# whatever other fields assuming the createEntry
# returns an object and not a scalar
}
}
`
Note that the type you use will depend on the type specified by the input argument -- replace SomeInputObjectType with the appropriate type name. If the vendor did not provide adequate documentation for their service, you should at least have access to a GraphiQL or GraphQL Playground instance where you can look up the argument's type. Otherwise, you can use any generic GraphQL client like Altair and view the schema that way.
Once you've constructed your query, make the request like this:
const variables = {
input: {
title: obj.title,
...
}
}
const response = await fetch(YOUR_GRAPHQL_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query, variables }),
})
const { data, errors } = await response.json()

GraphQL string concatenation or interpolation

I'm using GitHub API v 4 to learn GraphQL. Here is a broken query to fetch blobs (files) and their text content for a given branch:
query GetTree($branch: String = "master") {
repository(name: "blog-content", owner: "lzrski") {
branch: ref(qualifiedName: "refs/heads/${branch}") {
name
target {
... on Commit {
tree {
entries {
name
object {
... on Blob {
isBinary
text
}
}
}
}
}
}
}
}
}
As you see on line 3 there is my attempt of guessing interpolation syntax, but it does not work - I leave it as an illustration of my intention.
I could provide a fully qualified name for a revision, but that doesn't seem particularly elegant. Is there any GraphQL native way of manipulating strings?
I don't think there's anything in the GraphQL specification that specifically outlines any methods for manipulating string values within a query.
However, when utilizing GraphQL queries within an actual application, you will provide most of the arguments for your query by utilizing variables that are passed alongside your query inside your request. So rather than being done inside your query, most of your string manipulation will be done within your client code when composing the JSON that will represent your variables.

rally-node Add new item to collection

Using the rally-node toolkit, I'm getting an error message returned when attempting to add new Changeset, with new Changes inline, to an existing Userstory. When I have the new Changes commented out there's the Changeset is added as expected. It seems to be something specifically with the Change data that I can't figure out.
Add call:
rallyApi.add({
"ref":"https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement/91834286580",
"collection":"Changesets",
"data":[
{
"Author":{
"_ref":"https://rally1.rallydev.com/slm/webservice/v2.0/user/53634054872"
},
"CommitTimestamp":"2017-03-17T09:52:07-04:00",
"Message":"Feature/tags (#11)",
"Revision":"b8460460254cb79d3e72c98172c164f5c4d3493a",
"Uri":"https://ghe/org/repo/commit/b8460460254cb79d3e72c98172c164f5c4d3493a",
"Changes":[
{
"Action":"M",
"PathAndFilename":"file1.json",
"Uri":"https://ghe/org/repo/commit/b8460460254cb79d3e72c98172c164f5c4d3493a/file1.json"
},
{
"Action":"M",
"PathAndFilename":"file2.json",
"Uri":"https://ghe/org/repo/commit/b8460460254cb79d3e72c98172c164f5c4d3493a/file2.json"
}
],
"SCMRepository":{
"_ref":"https://rally1.rallydev.com/slm/webservice/v2.0/scmrepository/101417587520"
}
}
]
})
Returned error:
{ [Error: Could not create artifact to collection]
errors:
[ 'Could not create artifact to collection',
'Cannot parse object reference from "{null: {"Action": "M", "PathAndFilename": "file1.json", "Uri": "https://ghe/org/repo/commit/b8460460254cb79d3e72c98172c164f5c4d3493a/file1.json"}}"' ] }
It seems to be telling me it tried to find an existing change with that data, but I want to add a new change as specified in the docs and a recent question:
https://github.com/RallyTools/rally-node/wiki/User-Guide#add-to-a-collection
Rally API Add Tags to existing userstory NodeJS
I don't think you can do all of these things at the same time (although that would be pretty cool).
I'd first use the add method to add the changeset like you have specified, but without any changes. And then use the add method again to create the changes on that changeset. Does that work?

Access parameter from a resource defined using create_resources

I would like to know if it is possible to access a parameter from a class being instantiated using the create_resources function. I want to use that parameter in other class to conditionally install some things or not.
This is my scenario:
define myResource($myParam) { ... }
create_resources(myResource, $hashResources)
$hashResources = { "MyResource1" : { "myParam" : 1 },
"MyResource2" : { "myParam" : 2 }
}
myFancyPuppetClass($nameOfResource) {
if(******myParam from the resource defined with name $nameOfResource in the same catalog******) { ... }
}
Is this possible? If it is, how can I do the reference? Thank you!
Since the resources you are attempting to create are defined types, and the parameters in a defined resource are not accessible, this is not possible in the latest version of Puppet.
See a previous answer of mine regarding accessing parameters in defined resources for an alternative.

Resources